Поделиться через


ComboBox Control Overview (Windows Forms)

The Windows Forms ComboBox control is used to display data in a drop-down combo box. By default, the ComboBox control appears in two parts: 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. For more information on other styles of combo box, see When to Use a Windows Forms ComboBox Instead of a ListBox.

The SelectedIndex property returns an integer value that corresponds to the selected list item. You can programmatically change the selected item by changing the SelectedIndex value in code; the corresponding item in the list will appear in the text box portion of the combo box. If no item is selected, the SelectedIndex value is -1. If the first item in the list is selected, then the SelectedIndex value is 0. The SelectedItem property is similar to SelectedIndex , but returns the item itself, usually a string value. The Count property reflects the number of items in the list, and the value of the Count property is always one more than the largest possible SelectedIndex value because SelectedIndex is zero-based.

To add or delete items in a ComboBox control, use the Add, Insert, Clear or Remove method. Alternatively, you can add items to the list by using the Items property in the designer.

See Also

Tasks

How to: Add and Remove Items from a Windows Forms ComboBox, ListBox, or CheckedListBox Control

How to: Sort the Contents of a Windows Forms ComboBox, ListBox, or CheckedListBox Control

How to: Access Specific Items in a Windows Forms ComboBox, ListBox, or CheckedListBox Control

How to: Bind a Windows Forms ComboBox or ListBox Control to Data

How to: Create a Lookup Table for a Windows Forms ComboBox, ListBox, or CheckedListBox Control

Reference

ComboBox

ListBox Control Overview (Windows Forms)

Concepts

When to Use a Windows Forms ComboBox Instead of a ListBox

Other Resources

Windows Forms Controls Used to List Options