ComboBox 控件概述(Windows 窗体)ComboBox Control Overview (Windows Forms)

Windows 窗体ComboBox控件用于显示下拉组合框中的数据。The Windows Forms ComboBox control is used to display data in a drop-down combo box. 默认情况下,ComboBox控件将显示在两个部分: 上半部分是允许用户键入列表项的文本框。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. 有关其他样式组合框的详细信息,请参阅何时使用 Windows 窗体 ComboBox Instead of ListBoxFor more information on other styles of combo box, see When to Use a Windows Forms ComboBox Instead of a ListBox.

SelectedIndex属性返回对应的整数值到所选的列表项。The SelectedIndex property returns an integer value that corresponds to the selected list item. 你可以以编程方式更改选定的项,通过更改SelectedIndex代码中的值; 在组合框的文本框部分中将显示在列表中的相应项。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. 如果未不选择任何项,SelectedIndex值为-1。If no item is selected, the SelectedIndex value is -1. 如果选择列表中的第一项,则SelectedIndex值为 0。If the first item in the list is selected, then the SelectedIndex value is 0. SelectedItem属性是类似于SelectedIndex,但返回项本身,而通常一个字符串值。The SelectedItem property is similar to SelectedIndex , but returns the item itself, usually a string value. Count属性反映了在列表中,项的数目和的值Count属性始终为一个超过最大可能SelectedIndex值,因为SelectedIndex是从零开始。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.

若要添加或删除中的项ComboBox控制,请使用AddInsertClearRemove方法。To add or delete items in a ComboBox control, use the Add, Insert, Clear or Remove method. 或者,您可以向列表添加项使用Items在设计器中的属性。Alternatively, you can add items to the list by using the Items property in the designer.

请参阅See also