Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sorting by columns in a grid
Message
From
05/11/2004 09:41:34
 
 
To
05/11/2004 09:17:25
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP1
Miscellaneous
Thread ID:
00958466
Message ID:
00958483
Views:
19
>I have a grid which the user can sort by any of the columns.
>
>Until recently, the user did this by right-clicking to get a pop-up menu, and one of the choices allowed sorting by the selected column. The sort routine would always do a "GOTO TOP" to put the user back at the top of the newly sorted grid.
>
>I have recently added the capability to click on the column header, which sorts immediately (no pop-up).
>
>Since these are now duplicate capabilities, I have been asked to modify the behavior when right-clicking on one of the rows in the grid: if the user chooses the option to sort the column, he still wants the grid sorted, BUT he wants to remain on the same record that he right-clicked on.
>
>I can't get this to work. Previously, by code looked like:
>
>    INDEX ON bla-bla-bla
>    GOTO TOP
>
>which works properly, sending the user to the top record.
>
>The new code, which does not work properly, looks like:
>
>    lnRecNO=RECNO()
>    INDEX ON bla-bla-bla
>    GOTO (lnRecNO)
>
>This code doesn't fail, but appears to place the user on some random record in the grid.
>In fact, on some occasions, it even gets the correct record.
>
>Any suggestions?
>Thanks

No random, it is deterministic.

When you are into the grid, the grid uses it's internal values for
control the Recordsource
- the VFP implementation it is not correct:
VFP have internally the
- FirstRelativeRowRecNO ( RECNO() of the first line )
- the RelativeRow of the ActiveRow.
When you change the ROWS order, VFP repaint the Grid,
start at previous FirstRelativeRowRecNO,
count RelativeRow-1 steps and set this row like ActiveRow.
Of Course the order is changed, and then the new active row
can to be fully incorrelate and to seem random.

Try:
lnRecNO=RECNO()
INDEX ON bla-bla-bla
GOTO (lnRecNO)
Grid::Refresh
if you want that the relativerow ( if possible )
don't change, you have to control the position with DoScroll()

Fabio
Previous
Reply
Map
View

Click here to load this message in the networking platform