Redigera

Dela via


ListBox.ObjectCollection.Insert(Int32, Object) Method

Definition

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

public:
 virtual void Insert(int index, System::Object ^ item);
public:
 void Insert(int index, System::Object ^ item);
public void Insert (int index, object item);
abstract member Insert : int * obj -> unit
override this.Insert : int * obj -> unit
member this.Insert : int * obj -> unit
Public Sub Insert (index As Integer, item As Object)

Parameters

index
Int32

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

item
Object

An object representing the item to insert.

Implements

Exceptions

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

item is null.

Remarks

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.

Applies to