ComboBox Control.
The ComboBox control is typically used for selecting text field options from a the
list. If the dropdownstyle is set to dropdownlist the user can only select one of
the dropdown items within the list. If the dropdownstyle is set to dropdown, the
user can enter text into the text field. If the dropdownstyle is set to simple,
the ComboBox control acts as a listbox control with a searchable textbox.

Namespace: System.Windows.Forms
Assembly: Systems.Windows.Forms.dll
using System.Windows.Forms;
Calling: System.Windows.Forms.ComboBox
Creating a new System.Windows.Forms.ComboBox control.
ComboBox comboBox1 = new ComboBox();
Adding the button control to a Windows form.
this.Controls.Add(comboBox1);
Placing the button on the form at a specific location.
comboBox1.Location = new Point(50, 50);
Assigning a text value to a button control.
comboBox1.Text = "Enter";
Assigning an index change event to the ComboBox control.
comboBox1_SelectedIndexChanged+=new EventHandler(comboBox1_SelectedIndexChanged);
Responding to the ComboBox click event.
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
//The MessageBox is part of the System.Windows.Forms namespace.
MessageBox.Show("HelloWorld");
}
Changing the background color of the ComboBox control.
comboBox1.BackColor = System.Drawing.Color.Red;
To disable the ComboBox control.
comboBox1.Enabled = false;
Here the ComboBox control is still visible (partially faded) but will not respond
to any events. To re-enable the ComboBox control you would set the Enabled property
to true. When adding the ComboBox control the default setting is for the control
to be Enabled.
The ComboBox
includes the AutoComplete properties. You can set the AutoComplete source to FileSystems,
History list, Urls etc.
Setting the ComboBox control to an AllUrl source.
comboBox1.AutoCompleteSource = AutoCompleteSource.AllUrl;
The AutoComplete mode allows you to control how the ComboBox will handle the AutoCompleteSource
data.
comboBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
|