ListBox.ObjectCollection.Insert(Int32, Object) ListBox.ObjectCollection.Insert(Int32, Object) ListBox.ObjectCollection.Insert(Int32, Object) ListBox.ObjectCollection.Insert(Int32, Object) Method

定义

将一个项插入列表框中指定的索引处。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, object item);
abstract member Insert : int * obj -> unit
override this.Insert : int * obj -> unit
Public Sub Insert (index As Integer, item As Object)

参数

index
Int32 Int32 Int32 Int32

插入项的从零开始的索引位置。The zero-based index location where the item is inserted.

item
Object Object Object Object

表示要插入的项的对象。An object representing the item to insert.

实现

异常

index 参数小于零或大于 ListBox.ObjectCollection 类的 Count 属性的值。The index parameter is less than zero or greater than value of the Count property of the ListBox.ObjectCollection class.

注解

此方法,可在特定位置处插入项ListBoxThis method enables you to insert an item at a specific position within the ListBox. 如果Sorted的属性ListBox设置为 true,该项将添加在已排序的列表,而不考虑中指定的值中的正确位置中index参数。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. 当一个对象添加到集合中,ListBox首先检查以查看是否DisplayMember属性的ListControl类具有中取得项文本时指定为引用的对象的成员的名称。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. 如果DisplayMember属性不具有指定的成员,ListBox然后调用ToString对象以获取要在列表中显示的文本的方法。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.

适用于