listbox/combobox programmatic selection

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
Hi AbeR, have you tried...

myList.itemdata(n)

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

Luck
 
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
 
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
 
Back
Top