Set value of combo box to first item in list

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?
 
A

Al Reid

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
 
R

Rick Rothstein

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
 
N

Newbie

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
 
A

Al Reid

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

Bruce M. Thompson

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

Bruce M. Thompson

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.
 

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