ComboBox.ObjectCollection.Add(Object) 方法


將項目加入至 ComboBox 的項目清單。Adds an item to the list of items for a ComboBox.

 int Add(System::Object ^ item);
public int Add (object item);
member this.Add : obj -> int
Public Function Add (item As Object) As Integer



物件,表示要加入至集合中的項目。An object representing the item to add to the collection.


集合中的項目之以零起始的索引。The zero-based index of the item in the collection.



item 參數為 nullThe item parameter was null.


這個方法會將專案加入至下拉式方塊。This method adds an item to the combo box. 如果 ComboBoxSorted 屬性設定為 [true],則會依字母順序將專案插入清單中。If the Sorted property of the ComboBox is set to true, the item is inserted into the list alphabetically. 否則,專案會插入至清單的結尾。Otherwise, the item is inserted at the end of the list.

專案的視覺標記法會顯示在下拉式方塊中。A visual representation of the item is displayed in the combo box. 此內容表示是由 DisplayMember 屬性所指定。This content representation is specified by the DisplayMember property. 如果 DisplayMember 屬性是 null,則會呼叫專案的 ToString 方法來取得下拉式方塊中顯示的字串;否則,會顯示 [DisplayMember] 屬性所指定之預存物件的屬性。If the DisplayMember property is null, the item's ToString method is called to obtain the string that is displayed in the combo box; otherwise, the property of the stored object as specified by the DisplayMember property is displayed. 如果空間不足,無法儲存新專案,就會發生 SystemExceptionA SystemException occurs if there is insufficient space available to store the new item. 若要將一組專案新增至下拉式方塊,最好使用 AddRange 方法。To add a set of items to the combo box it is best to use the AddRange method. 如果您選擇使用 Add 方法,將數個專案新增至下拉式方塊,請使用 BeginUpdate 方法,在您的新增期間暫止重新繪製,而 EndUpdate 方法則會繼續重新繪製。If you choose to use the Add method to add a number of items to the combo box, use the BeginUpdate method to suspend repainting during your add and the EndUpdate method to resume repainting. 您可以使用 Insert 方法,在清單中指定專案的新增位置。You can use the Insert method to specify the location in the list where an item is added. 當物件新增至集合時,ComboBox 會呼叫物件的 ToString 方法,以取得要顯示在清單中的字串。When an object is added to the collection, the ComboBox calls the object's ToString method to obtain the string to display in the list.