Highlighting and observing a record in a listbox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a listbox on one of my forms. Several of the operations that this
application performs require that a single item be selected. One of these
operations results in the list being requeried. What I am trying to do is
reselect the item that was last selected prior to the requery, and make the
selected item visible in the list.

Unfortunately, the recordset that populates the list has a complex (3 field)
PK, so there is no unique value in the Bound column.

I started out by storing the listindex and using that to do the
highlighting, until I realized that the elements of the list, and their sort
order may change in the process of requering the list. So then I wrote some
code to loop through the list and test the three fields of the PK; when the
code finds the line of the list that contains the information that was
previously selected, it selects that record, and exits the loop.

Unfortunately, if the item is outside the portion of the list that is
currently visible, it stays hidden until I scroll up or down to find the
record. Is there any way to force the listbox to display records starting at
a particular index?
 
Dale said:
I have a listbox on one of my forms. Several of the operations that this
application performs require that a single item be selected. One of these
operations results in the list being requeried. What I am trying to do is
reselect the item that was last selected prior to the requery, and make the
selected item visible in the list.

Unfortunately, the recordset that populates the list has a complex (3 field)
PK, so there is no unique value in the Bound column.

I started out by storing the listindex and using that to do the
highlighting, until I realized that the elements of the list, and their sort
order may change in the process of requering the list. So then I wrote some
code to loop through the list and test the three fields of the PK; when the
code finds the line of the list that contains the information that was
previously selected, it selects that record, and exits the loop.

Unfortunately, if the item is outside the portion of the list that is
currently visible, it stays hidden until I scroll up or down to find the
record. Is there any way to force the listbox to display records starting at
a particular index?


Nothing built in for that, but take a look at:
http://www.lebans.com/SelectRow.htm

Personally, I never use a list box, preferring to trade more
work for the flexibility of a continuous subform.
 
Back
Top