A ComboBox displays a text box edit field combined with a ListBox, enabling the user to select items from the list or to enter new text. The default behavior of ComboBox displays an edit field with a hidden drop-down list. The DropDownStyle property determines the style of combo box to display. You can enter a value that provides a simple drop-down, where the list always displays, a drop-down list box, where the text portion is not editable and you must select an arrow to view the drop-down list box, or the default drop-down list box, where the text portion is editable and the user must press the arrow key to view the list. To display a list that the user cannot edit, use a ListBox control.
To add objects to the list at run time, assign an array of object references with the AddRange method. The list then displays the default string value for each object. You can add individual objects with the Add method.
In addition to display and selection functionality, the ComboBox also provides features that enable you to efficiently add items to the ComboBox and to find text within the items of the list. With the BeginUpdate and EndUpdate methods, you can add a large number of items to the ComboBox without the control being repainted each time an item is added to the list. The FindString and FindStringExact 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 Text property to specify the string displayed in the editing field, the SelectedIndex property to get or set the current item, and the SelectedItem property to get or set a reference to the object.
Note |
|---|
| If you have a ListBox, ComboBox, or 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. |