Reselect items of the listbox after its requery

mahmudich

Registered User.
Local time
Tomorrow, 09:25
Joined
Feb 10, 2003
Messages
73
Hi everybody!
I’m wondering if anyone had similar problem?

I have a listbox with 4 columns, which is refreshed by a query. Every column has a corresponding button, which can change the order of that column. The problem is every time I change the order of any column I loose the rows I selected before because they become unselected.

I know the SELECTED(“row_index”) property to select particular row and I could extract the item’s data of the items I selected using ITEMDATA(“row_index”) and the loop function.

Example:
‘this is data from one of the columns I selected before changing the order of the listbox
strList = 123,134,323

I press the button and REQUERY the listbox, so all items unselected. Now I would like to see those items selected again.
So, how to get row_indexs of these items (123,134,323) and then I would use SELECTED property to reselect them again.


Thanks in advance
 
M,

Do you want to re-select the same record(s) that were selected?
Do you want to re-select the same physical row(s) that were selected?

Code:
                   John     Smith   123   A
Row Selected -->   Al       Jones   134   X
                   Henry    Ward    323   C

Change to sort on this column -+
                               |
                               V
Was Selected -->   Al       Jones   134   X
Select Now?? -->   John     Smith   123   A
                   Henry    Ward    323   C

Wayne
 
For example you had selected Al and Henry:

John Smith 123 A
Row Selected --> Al Jones 134 X
Row Selected --> Henry Ward 323 C

Change to sort on this column -+

I need Al and Henry to be selected again:
|
V
Row reSelected --> Al Jones 134 X
John Smith 123 A
Row reSelected --> Henry Ward 323 C

Thanks WayneRyan
 
m,

Don't thank me yet, we haven't done anything.

Things we know:

1) The ListBox is not going to "remember" which rows were selected
after the requery.

2) After the Requery, you want to "re-highlight" the same records. Not
the same physical rows in the ListBox, but the same records.

3) To identify which records to "re-highlight", you'll need to save the
PK for each record somewhere. This also assumes that the PK is
contained in one of the columns of the ListBox (even an invisible, new
column). You can't use any of the columns in your current ListBox
if there are any duplicates.

Off the top of my head, I'd suggest:

a) Make a table to store your selected PKs

b) When you do a requery: Delete all from table, Loop through the ListBox
and add all selected PKs to the Table.

c) ReQuery the ListBox

d) Loop through the ListBox and if the PK is in the table, highlight the
entry.

Just a first idea,
Wayne
 

Users who are viewing this thread

Back
Top Bottom