Name

ComboBox

Synopsis

This control represents an edit box with a drop-down list—a standard Win32 combobox. It extends the base ListControl that supports a variety of list-like controls. In addition to the standard control facilities, you can set the DropDownStyle property, which determines whether the edit box allows you to type into it and whether the list view is always visible, and set the DropDownWidth property of the drop-down list. You can set the IntegralHeight property, which can automatically adjust the height of the control to ensure that only whole items are displayed. The MaxDropDownItems property sets the maximum number of items that will be displayed in the drop-down list (without scrolling), and the MaxLength property sets the number of characters allowed in the edit field.

The selected item can be retrieved through the SelectedItem and SelectedIndex properties, which should not be confused with the SelectedText property, which gets the selected text in the edit field.

You can add and remove objects from the Items collection to alter the contents of the listbox, and the very useful members FindString() and FindStringExact() can help you locate a particular item in the list. Finally, you can select the text in the edit field using Select() or SelectAll().

Unfortunately, the implementation of ComboBox in Version 1.0 of the framework is something of a minor fiasco. The edit control doesn’t support the standard pop-up menus, and the selection and edit behavior is idiosyncratic ...

Get .NET Windows Forms in a Nutshell now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.