Set value of combo box to first item in list

  • Thread starter Thread starter Newbie
  • Start date Start date
N

Newbie

Hi

I have a combo box that is populated using the AddItem method

How can I set the value of the combobox to the first item in the list?
 
You can select an item by setting the ListIndex Property. To set the to the first combo item use:

ComboBox1.ListIndex = 0

or to select the last item use

ComboBox1.ListIndex = ComboBox1.ListCount - 1
 
I have a combo box that is populated using the AddItem method
How can I set the value of the combobox to the first item in the list?

There are several properties available with the ListBox (as with any
control)... one of them for the ListBox is ListIndex which returns the
location for the highlighted item. That property also allows you to set the
location for the highlight. The list in the ListBox is a zero-based list,
so...

List1.ListIndex = 0

will force the highlight to the first item in the list. This, as well as the
other properties, is covered in the VB help files.

Rick - MVP
 
Thanks - works a treat
Al
Al Reid said:
You can select an item by setting the ListIndex Property. To set the to the first combo item use:

ComboBox1.ListIndex = 0

or to select the last item use

ComboBox1.ListIndex = ComboBox1.ListCount - 1

--
Al Reid

"It ain't what you don't know that gets you into trouble. It's what you know
for sure that just ain't so." --- Mark Twain
 
Rick,

Happy Monday! Everything you stated is correct, except that you answered the wrong question <g>. The bright side is that the OP
will not have to ask the same question as it applies to a ListBox control.
 
Happy Monday! Everything you stated is correct, except that you answered the
wrong question said:
will not have to ask the same question as it applies to a ListBox control.

The *same* answer applies to both listboxes and combo boxes.
 
I have a combo box that is populated using the AddItem method
How can I set the value of the combobox to the first item in the list?

To select the first value in a combo box regardless of its "ColumHeads" setting
(watch line wrap - it's all on one line):

'**
Me.Combo1.Value = Me.Combo1.ItemData(Abs(Me.Combo1.ColumnHeads))
'**

You need to replace every instance of "Combo1" with the name of your combo box.
 
Back
Top