System.Windows.Forms.ComboBox Class

Represents a Windows combo box control.

See Also: ComboBox Members

Syntax

[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.ComponentModel.DefaultBindingProperty("Text")]
[System.ComponentModel.Designer("System.Windows.Forms.Design.ComboBoxDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.ComponentModel.Design.IDesigner")]
[System.ComponentModel.DefaultEvent("SelectedIndexChanged")]
[System.ComponentModel.DefaultProperty("Items")]
public class ComboBox : ListControl

Remarks

A System.Windows.Forms.ComboBox displays a text box combined with a System.Windows.Forms.ListBox, which enables the user to select items from the list or enter a new value.

The ComboBox.DropDownStyle property specifies whether the list is always displayed or whether the list is displayed in a drop-down. The ComboBox.DropDownStyle property also specifies whether the text portion can be edited. See System.Windows.Forms.ComboBoxStyle for the available settings and their effects. There is no setting to always display the list and disallow entering a new value. To display a list to which no new values can be added, use a System.Windows.Forms.ListBox control.

To add or remove objects in the list at run time, use methods of the System.Windows.Forms.ComboBox.ObjectCollection class (through the ComboBox.Items property of the System.Windows.Forms.ComboBox). You can assign an array of object references with the System.Windows.Forms.ComboBox.ObjectCollection.AddRange(Object[]) method. The list then displays the default string value for each object. You can add individual objects with the System.Windows.Forms.ComboBox.ObjectCollection.Add(object) method. You can delete items with the System.Windows.Forms.ComboBox.ObjectCollection.Remove(object) method or clear the entire list with the System.Windows.Forms.ComboBox.ObjectCollection.Clear method.

In addition to display and selection functionality, the System.Windows.Forms.ComboBox also provides features that enable you to efficiently add items to the System.Windows.Forms.ComboBox and to find text within the items of the list. With the ComboBox.BeginUpdate and ComboBox.EndUpdate methods, you can add a large number of items to the System.Windows.Forms.ComboBox without the control being repainted each time an item is added to the list. The ComboBox.FindString(string) and ComboBox.FindStringExact(string) methods enable you to search for an item in the list that contains a specific search string.

You can use these properties to manage the currently selected item in the list, the ComboBox.Text property to specify the string displayed in the editing field, the ComboBox.SelectedIndex property to get or set the current item, and the ComboBox.SelectedItem property to get or set a reference to the object.

Note:

If you have a System.Windows.Forms.ListBox, System.Windows.Forms.ComboBox, or System.Windows.Forms.CheckedListBox on a base Windows Forms page and want to modify the string collections of those controls in a derived form, the string collections of those controls in the base form must be empty. If the string collections are not empty, they become read-only when you derive another form.

Requirements

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0