Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problems with variable reference to recordsource in grid
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00477049
Message ID:
00477158
Vues:
37
David,
When a container loads, all of the controls inside it are initiated, then the container itself. This is true whether the container is a form, pageform, container, etc.

In your case, I'd add a container property to hold the grid RecordSource and also a method which assigns the RecordSource to the grid. This method would be called from the Container's INIT() code. We'll call it GridSetup() here.

In the container property you just type the cursor or table alias (no quote marks). Leave the Grid Recordsource empty. In the GridSetup code you'd put
cRS = this.GridRecordSource
This.MyGrid.Recordsource = cRS
This.MyGrid.refresh()
You could also add code describing grid headers, column widths, etc. here, as these would vary with your different recordsources.

To change a grid RecordSource programmatically, you must follow several steps:
...MyGrid.RecordSource = ""   
...MyGrid.RecordSource = "CursorNew"
...MyGrid.Refresh()
The first line is not actually needed, but is a good habit to get into. If you are rebuilding an SQL cursor (using the SELECT .... command) a grid will lose all of its programmatic formatting unless you set the RecordSource to "" first.

The code above could go into the form method I suggested above - the grid could be completely reformatted with a single method call.

Form (or container) Properties assume that a value is a string. If you want to use a variable, put an = sign in front of the form property. For example, if you have a global variable (hey this is an example!) "MyGlobalVar" which has the value "ABCDE" you can assign a form property MyFormProp and give it the value "=MyGlobalVar" (don't put the quote marks in the form property).

Then your textbox Value would be "=thisform.MyFormProp" (again no quotes). When you load the form the textbox will show the value of the MyGlobalVar variable. I hope this is clear.

HTH
Barbara

>I am attempting to make my grid more generic and accept any recordsource. The grid is inside a container. (The container/grid and other controls are a class in my library) I would like to have the recordsource for the grid be specified by setting a property of the container. Then all other controls, in the container and the grid as well, can reference that property value. But I am having problems. I don't know when the record source is evaluated.
>Say for example that the container has the value: cursurques
>Dumb question: How does VFP evaluate whether a value in a property is character or numeric or a variable itself ? Shouldn't =somvar evalutate the variable,
>whereas something like cursurques evaluates to the string cursurques ?
>
>What value should go in my container property , for a table or cursor alias ?
>
>What value should go in the recordsource property for the grid, ie. how do I reference the cursor or table alias in the container property ?
>
>If I change the value in the container property at runtime, when/how will the recordsource property know when to reevaluate recordsource property of the grid ?
>
>TIA
Barbara Paltiel, Paltiel Inc.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform