Library tutorials & articles
Combo Box
- Introduction
- Styles
- Properties and Events
- Adding items
- Removing items
- Getting the selected item
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.
Related articles
Related discussion
-
VB6 Runtime error 381 subsript out of range Error
by Uncle (2 replies)
-
passing and reading parameters from using Shell
by jigartoliya (0 replies)
-
Convert C++ code to VB6
by mawcot (4 replies)
-
listbox scrollbar
by Dennijr (10 replies)
-
Can you describe Above simple VB6 code?
by pramodmca09 (0 replies)
Related podcasts
-
Christian Beauclair
14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...
Try this:
ComboBox1.Items.Add("Text")
It's pretty flexible, you can put just about anything in there:
ComboBox1.Items.Add("Text" & RichTextBox1.Text & someVariable & etc.)
- Vincent
The .AddItem is to add items to the Combo Box at run time. This is normally the preferred way of doing this instead of doing it through the properties of the Combo Box.
Usage:
Combo1.AddItem "String"
Yeah, I was getting an error like "Invalid procedure call or argument" (Runtime error 5). It seems to work if I remove the index # (rather than Combo1.Additem "Blah" 2, just Combo1.Additem "Blah").
Combo1.AddItem tells me that it's a wrong code.
This thread is for discussions of Combo Box.