ComboBox in Visual Basic .NET
Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013
This lesson describes the ComboBox control
The ComboBox control contains a text box where the user can enter a value and also provides a list box or drop-down list where the user can select a value.
Depending on the control's DropDownStyle property you define how this control's text box, list box or drop-down list will work.
If you set the DropDownStyle to Simple, the ComboBox will display a text box and a list.
Then the user can type a value in the text box, or select one from the list. The user can type any text in the text box, even if it does not appear in the list.
If you set the DropDownStyle to DropDown, the ComboBox will display a text box and a drop-down list.
Then the user can type a value in the text box or click the drop-down arrow to the right of the text box (the control displays the list where the user can select an item).
Same as the previous selection, the user can type any text in the text box, even if it does not appear in the list.
If you set the DropDownStyle to DropDownList, the ComboBox is going to display a non-editable text box and a drop-down list.
Then if the user clicks the control, the ComboBox displays a drop-down list exactly as it does when DropDownStyle is DropDown, and the difference is that the user must select an item from the list.
If the user sets focus to the control and types a letter, the control selects the next item in the list that begins with that letter.
However if the user presses the same letter once again, the control moves to the next choice beginning with that letter.
For i As Integer = 0 To states.GetUpperBound(0) Dim state As String = states(i) CBox_Simple.Items.Add(state) CBox_DropDown.Items.Add(state) CBox_DropDownList.Items.Add(state) Next ' set the default selections CBox_Simple.SelectedIndex = 0 CBox_DropDown.SelectedIndex = 0 CBox_DropDownList.SelectedIndex = 0
Previous Lesson | Next Lesson