ComboBox Control

ComboBox Control

The ComboBox control is a combination of the text box and list box. The top part is a text box that allows the user to type a list item. The second part is a list box that displays a list of items from which the user can select one.

image 9

You can add or remove items to a ComboBox either at design time or at run time. Using items property, you can add or remove items in the ComboBox. The first item will have index 0, the next item will have index 1, and so on in the ComboBox. 

  • To add items at run time, you can use Items. Add OR Items. Insert OR Items.AddRange method.
  • To remove items at run time, you can use Items.Remove OR Items.RemoveAt method.
  • To remove all the items at run time, you can use Items. Clear method.
  • To count the total numbers of items in the combo box at run time, you can use the Count property of the Items collection. 

Property :  

(1) DropDownStyle : This property represents the style (types) of the combo box control. The different styles (types) are

  1. Simple
  2. DropDown &
  3. DropDownList.
  1. Simple: It is the ComboBox without drop down arrow. It contains text box & list box that does not drop down. User can select from the list or type in to the text box.
  2. DropDown : It is the by default style. User can either type the text directly or select the item from the drop down list.
  3. DropDownList : Display list box when user click on the drop down arrow. User can only select an item from the list; user cannot enter text in the text box.

2. MaxDropDownItems : This property represents the maximum numbers of items that will be display in the drop down portion when the drop down arrow on the ComboBox control is click.

3. Text : Gets or searches for the text of the currently selected item in the ComboBox. This property represents the text of the item that is currently selected.

4. Items : Using items property you can add or remove items in the ComboBox. The first item will have index 0, the next item will have index 1, and so on in the ComboBox. The items in the combo box are stored in the Items collection.

5. SelectedItem (Only available at run time, Dynamic property): This property represents the item that is currently selected in the combo box.

6. SelectedIndex (Only available at run time, Dynamic property) : This property represents the index of the currently selected item in the ComboBox. If no item is selected in the Listbox, then SelectedIndex property will return -1.

Note: There is no SelectedItems & SelectedIndices property exists for ComboBox control.

Methods : 

  • FindString
  • FindStringExact

Events :

SelectedIndexChanged : Occurs when the value of the SelectedIndex property has changed.