Export (0) Print
Expand All

ListBox.ObjectCollection.Insert Method

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
)

Parameters

index
Type: System.Int32

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

item
Type: System.Object

An object representing the item to insert.

Implements

IList.Insert(Int32, Object)

ExceptionCondition
ArgumentOutOfRangeException

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

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.

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

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft