ListBox.ObjectCollection.Insert Method (Int32, Object)


Inserts an item into the list box at the specified index.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public void Insert(
	int index,
	object item


Type: System.Int32

The zero-based index location where the item is inserted.

Type: System.Object

An object representing the item to insert.

Exception Condition

The index parameter is less than zero or greater than value of the Count property of the ListBox.ObjectCollection class.


item is null.

This method enables you to insert an item at a specific position within the ListBox. If the Sorted property of the ListBox is set to true, the item is added in the correct position within the sorted list regardless of the values specified in the index parameter. When an object is added to the collection, the ListBox first checks to see if the DisplayMember property of the ListControl class has the name of a member from the object specified to reference when obtaining the item text. If the DisplayMember property does not have a member specified, the ListBox then calls the ToString method of the object to obtain the text to display in the list.

.NET Framework
Available since 1.1
Return to top