select item in listbox

  • Thread starter Thread starter neouia777
  • Start date Start date
Hi i have listbox in form i like make the listbox.text = the first
item. pls help me


For a single-select listbox:

With lstYourListboxName
.Value = .ItemData(Abs(.ColumnHeads))
End With

If you know it won't have column headers:

With lstYourListboxName
.Value = .ItemData(0)
End With

For a multiselect list box:

With lstYourListboxName
.Selected(Abs(.ColumnHeads)) = True
End With
 
Linq Adams via AccessMonster.com said:
YourListBox.SetFocus
YourListBox.ListIndex = 0


Note that:

1. This doesn't work for multiselect list boxes. For them, the ListIndex
property is independent of the items selected.

2. This method requires you to setfocus to the list box, when otherwise you
wouldn't have to.
 
Linq Adams via AccessMonster.com said:
Actually, it does work for Multi-select Extended, not for Simple, but
you're
right about setting focus. But after doing so, you can then set focus
elsewhere and the selection remains.

You're right -- I'd forgotten about extended mode, probably because I never
use it. I still don't much care for solutions that require setting the
focus to a control, especially when you don't need to. But as long as we're
counting up different ways to to skin cats, your suggestion certainly
qualifies.

I wonder if there are any others ...
 
Back
Top