Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ComboBox.ObjectCollection.Add Method

This method supports the .NET Framework infrastructure and is not intended to be used directly from your code.

Adds an item to the list of items for a ComboBox.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public int Add (
	Object item
)
public int Add (
	Object item
)
public function Add (
	item : Object
) : int

Parameters

item

An object representing the item to add to the collection.

Return Value

The zero-based index of the item in the collection.

Exception typeCondition

ArgumentNullException

The item parameter was a null reference (Nothing in Visual Basic).

This method adds an item to the combo box. 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. This content representation is specified by the DisplayMember property. If the DisplayMember property is a null reference (Nothing in Visual Basic), 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. A SystemException occurs if there is insufficient space available to store the new item. To add a set of items to the combo box it is best to use the AddRange method. 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. You can use the Insert method to specify the location in the list where an item is added. 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.

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft