select item in listbox

N

neouia777

Hi i have listbox in form i like make the listbox.text = the first
item. pls help me
 
D

Dirk Goldgar

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
 
D

Dirk Goldgar

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.
 
D

Dirk Goldgar

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 ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top