- A ComboBox control displays a list of items in a drop-down list.
- ComboBox control is a combination of a text box in which a user can enter a drop-down list from where the user can select an item.
- You can place a ComboBox control on the form by drag and drop it from the toolbox. The ComboBox control looks like as follows:
Properties of ComboBox Control
Some of the commonly used properties of ComboBox Control are listed below in the Table:
Methods of ComboBox Control
Some of the commonly used methods of ComboBox Control are listed below in the Table:
Events of ComboBox Control
Some of the commonly used Events of ComboBox Control are listed below in the Table:
Here is a simple example of ComboBox control. To understand the use of the ComboBox control follows the given steps:
- Add one ComboBox control to the Form by drag and drop it from the Toolbox.
- Select the ComboBox and press F4 key to open its properties window and click on the ellipse (…) button besides the items option this will open a String Collection Editor. Add the following items and click on OK button to close the dialog box as given in the below diagram:
- Now set the Text property of the ComboBox to ‘Select One’.
- Now double click on the combo-box in the form and add the following code in its code window:
- In the above code ComboBox1_SelectedIndexChanged method handles the SelectedIndexChanged event of the ComboBox. Whenever we select an item from the combobox a message is displayed using the MsgBox method.
- Now run the application using F5 key. This will produce a Form at run time, Select any item from the combo box a message box with selected color will be displayed as given below in the diagram: