listbox/combobox programmatic selection


G

Guest

I'm having a brain hicup! Can someone please remind me of the method to
select in code an item from a listbox or combobox?

ItemSelected reads what has been clicked on. I want to select from the
listIndex an item.

Any help would be extremely appreciated!

Thank you
 
Ad

Advertisements

G

Guest

Hi AbeR, have you tried...

myList.itemdata(n)

where n is a position index starting from 0 (zero)

Luck
 
G

Guest

Thank you.

Jonathan Parminter said:
Hi AbeR, have you tried...

myList.itemdata(n)

where n is a position index starting from 0 (zero)

Luck
 
G

Guest

Thanks for the feedback. Unfortunately the .itemdata(n) method is read-only
unless I'm missing something. There must be a method that lets us select row
0 for example instead of having to figure out the value of the control and
setting the control to that value.

I'm still open for suggestions. Thanks in advance.
- Abe
 
Ad

Advertisements

D

Dirk Goldgar

AbeR said:
I'm having a brain hicup! Can someone please remind me of the method
to select in code an item from a listbox or combobox?

ItemSelected reads what has been clicked on. I want to select from the
listIndex an item.

Any help would be extremely appreciated!

Thank you
Which item do you want to select? The first?

' For non-multiselect list box ...
With Me.lstMyList
.Value = .ItemData(Abs(.ColumnHeads))
End With

' For combo box ...
With Me.cboMyCombo
.Value = .ItemData(0)
End With

' For multiselect list box
With Me.lstMyList
.Selected(Abs(.ColumnHeads)) = True
End With

If your list boxes are single-select and don't use column headers, you
can use the same code for list boxes and combo boxes:

With Me.ctlMyListOrCombo
.Value = .ItemData(0)
End With
 

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

Top