Combo Box

Getting the selected item

To get the selected item you can use the Text and ListIndex property. They return the text and the index of the selected item respectively.

Var = Combo1.Text

where var is a string variable which will contain the text of the currently selected item

Var = Combo1.ListIndex

where var is a string variable which will contain the index of the currently selected item. Note that as index's start from 0, the first item on the list will return a ListIndex of 0. The following code displays a message box with the text and listindex of the current item

' Declare the variables
Dim sText As String
Dim lIndex As Long
' Fill the variables
sText = Combo1.Text
lIndex = Combo1.ListIndex + 1
' Display the message box
Msgbox sText & ", item number " & lIndex & " is currently selected.

You might also like...

Comments

About the author

James Crowley

James Crowley United Kingdom

James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audien...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The greatest performance improvement of all is when a system goes from not-working to working.” - John Ousterhout