Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Grid shows up correctly only the first time
Message
From
17/10/2005 15:50:18
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01059678
Message ID:
01059703
Views:
15
This message has been marked as the solution to the initial question of the thread.
>Hi everybody,
>
>I put a grid in the container control what I instantiate on the fly on the form. In this grid I set first column to use checkbox, I specified grid's layout, etc.
>
>I left RecordSource for the grid empty and control sources for the columns empty as well.
>
>I have the following code in Init method of the container:
>
>CREATE CURSOR cUsersList (lSelect L, cEmpName C(50), cUserID C(10), cPK C(16))
>	INDEX on UPPER(cEmpName) tag cEmpName
>	INDEX ON lSelect TAG lSelect
>	INSERT INTO cUsersList (cUserID, lSelect, cEmpName, cPK) ;
>	SELECT cUserID, .f. as lSelect, cEmpName, cUsgrlink_pk FROM c_AllUsers order by cEmpName
>	GO TOP IN cUsersList
>	this.grdUsers.RecordSource = 'cUsersList'
>	USE IN SELECT('c_AllUsers')
>
>E.g. I try to set RecordSource after the grid is already initialized.
>
>Now, when I first instantiate this container on the form, the grid displayes correctly. But if I remove the container and try to add it again, the nice grid layout and checkboxes are lost.
>
>The question is: why it works the first time and doesn't work the next time during form's life-time? How can I make it to work consistently correctly?
>
>Thanks in advance.

When the grid instantiates first time, does VFP sit on any alias? The grid, when it has no recordsource, assumes the currently selected alias as the recordsource, so when you set it to something, it reinitializes. Probably the first time you have no alias selected, so it doesn't have any recordsource and initializes as defined in the classlib, and next time it does have one selected, takes it for a recordsource, you set a new one, it rebuilds itself.

I see two ways around this: one is to Select 0 before creating the container (not sure that would work). The other is to have the Create Cursor, indexing and .recordsource in grid's .init(), and the rest in the init of the container. If you're not quite sure whether the cUserList cursor may already have some records, you may just zap it before inserting.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform