Редагувати

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


When to Use a Windows Forms ComboBox Instead of a ListBox

The ComboBox and the ListBox controls have similar behaviors, and in some cases may be interchangeable. There are times, however, when one or the other is more appropriate to a task.

Generally, a combo box is appropriate when there is a list of suggested choices, and a list box is appropriate when you want to limit input to what is on the list. A combo box contains a text box field, so choices not on the list can be typed in. The exception is when the DropDownStyle property is set to DropDownList. In that case, the control will select an item if you type its first letter.

In addition, combo boxes save space on a form. Because the full list is not displayed until the user clicks the down arrow, a combo box can easily fit in a small space where a list box would not fit. An exception is when the DropDownStyle property is set to Simple: the full list is displayed, and the combo box takes up more room than a list box would.

See also