ComboBox is a combination of a TextBox and a ListBox.
How use the ComboBox Control
Drag and drop ComboBox from toolbox on window Form.
Code:
'Here Item is added in combobox on form load
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ComboBox1.Items.Add("C#")'Add the First item in ComboBox
ComboBox1.Items.Add("J#")
ComboBox1.Items.Add("VB")
ComboBox1.Items.Add("Java")
End Sub
'Here show the selected item in Label2 on ComboBox SelectedIndexChanged event
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
' Assign the selected item in label
Label2.Text = "You selected " + ComboBox1.SelectedItem
End Sub
In above code Item is added dynamically so all Item in ComboBox1 will show at run time.
Run the project
When you select the given option then SelectedIndexChanged event will fire and selected item will show in the messagebox.
How set the AutoCompleteSource Properties
Choose AutoCompleteSource property of ComboBox is ListItem and also set AutoCompleteMode to suggest, append, or SuggestAppend.
When you type any text in the ComboBox then it searches the related item and if related item is available then it suggest the related item.
Leave Comment