set focus to particular entry in list box

jguscs

Registered User.
Local time
Today, 00:29
Joined
Jun 23, 2003
Messages
148
Is there a way to set the focus and select a particular entry in a list box?

This won't do it because it sets the focus to the list box object, but doesn't actually select an entry in the list box.
Me.ListBox.SetFocus

What I want is something more like this
Me.LstTables.ItemData(File).SetFocus
where File is either the index of a particular row in the list box or simply the row's contents.
 
Code:
Me.lstYourListBox.Selected([i]whateverRowYouWant[/i]) = True
 
Or this:
Code:
Me.lstYourListBox = 9
Where 9 is the value of the bound column of the listbox
 
I suppose if you rarely make changes to your recordset and, in SforSoftware's suggestion, have a record in the bound column with a value of 9 in your table.

If it is deleted, then you can't select it at all. I prefer to use the listbox's indexes than reply on the explicit value actually being in the listbox's entries.
 
You're right, but the reason I mentioned that option is that the value you want to select can be dependend of another (known) value, that's in another textbox of variabele.

It all depends on the way you want to use it.

Greetz,
Bert
 
I tried both methods and
Me.lstYourListBox = 9 did't work for me... I'm not sure, SforSoftware, but it seems like 9 refers to the index of the row (although you said it refers to the value of the bound column...)
Anyway,
Me.lstYourListBox.Selected(whateverRowYouWant) = True
works.
Thanks for your help.

Since I was trying to have a particular row selected, I used the
following code:

File = "The entry in the list box I'm looking for"
Dim Count As Integer
For Count = 0 To Me.ListBox.ListCount
If File = Me.ListBox.ItemData(Count) Then Exit For
Next Count
Me.ListBox.Selected(Count) = True
 

Users who are viewing this thread

Back
Top Bottom