articles

Home / DeveloperSection / Articles / ComboBox Control in VB.Net

ComboBox Control in VB.Net

Pushpendra Singh19539 13-Dec-2010

ComboBox is a combination of a TextBox and a ListBox.

How use the ComboBox Control

Drag and drop ComboBox from toolbox on window Form.

 

ComboBox Control in VB.Net

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 

ComboBox Control in VB.Net

When you select the given option then SelectedIndexChanged event will fire and selected item will show in the messagebox.

 

ComboBox Control in VB.Net

 

How set the AutoCompleteSource Properties

Choose AutoCompleteSource property of ComboBox is ListItem and also set AutoCompleteMode to suggest, append, or SuggestAppend.

ComboBox Control in VB.Net

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.

ComboBox Control in VB.Net


Updated 04-Mar-2020

Leave Comment

Comments

Liked By