• Have Any Question?
  • contact@eitworld.com

csharp.net combobox control





    • 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:

combobox-control

Properties of ComboBox Control

Some of the commonly used properties of ComboBox Control are listed below in the Table:

combobox-control

Methods of ComboBox Control

Some of the commonly used methods of ComboBox Control are listed below in the Table:

combobox-control

Events of ComboBox Control

Some of the commonly used Events of ComboBox Control are listed below in the Table:

combobox-control

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:

combobox-control

    • 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:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show(comboBox1.SelectedItem.ToString(),”selected”);
}

    • 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:

combobox-control

combobox-control
combobox-control


Real Time Web Analytics