ListView.ListViewItemCollection.Insert 方法

定义

将一项插入集合中指定索引处。Inserts an item into the collection at the specified index.

重载

Insert(Int32, String, String, String)

创建一个具有指定的键、文本和图像的新项,并将该项添加到集合中指定索引处。Creates a new item with the specified key, text, and image, and adds it to the collection at the specified index.

Insert(Int32, String, String, Int32)

创建一个具有指定的键、文本和图像的新项,并将该项插入到集合中指定索引处。Creates a new item with the specified key, text, and image, and inserts it in the collection at the specified index.

Insert(Int32, String, String)

创建一个具有指定的文本和图像的新项,并将该项插入到集合中指定索引处。Creates a new item with the specified text and image and inserts it in the collection at the specified index.

Insert(Int32, ListViewItem)

将现有的 ListViewItem 插入到集合中的指定索引处。Inserts an existing ListViewItem into the collection at the specified index.

Insert(Int32, String)

创建一个新项,并将其插入到集合中的指定索引处。Creates a new item and inserts it into the collection at the specified index.

Insert(Int32, String, Int32)

创建具有指定图像索引的新项,并将其插入到集合中的指定索引处。Creates a new item with the specified image index and inserts it into the collection at the specified index.

Insert(Int32, String, String, String)

创建一个具有指定的键、文本和图像的新项,并将该项添加到集合中指定索引处。Creates a new item with the specified key, text, and image, and adds it to the collection at the specified index.

public:
 virtual System::Windows::Forms::ListViewItem ^ Insert(int index, System::String ^ key, System::String ^ text, System::String ^ imageKey);
public virtual System.Windows.Forms.ListViewItem Insert (int index, string key, string text, string imageKey);
abstract member Insert : int * string * string * string -> System.Windows.Forms.ListViewItem
override this.Insert : int * string * string * string -> System.Windows.Forms.ListViewItem
Public Overridable Function Insert (index As Integer, key As String, text As String, imageKey As String) As ListViewItem

参数

index
Int32

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

key
String

项的 NameThe Name of the item.

text
String

项的文本。The text of the item.

imageKey
String

要为该项显示的图像的键。The key of the image to display for the item.

返回

添加到集合中的 ListViewItemThe ListViewItem added to the collection.

异常

index 参数小于零或大于 CountListView.ListViewItemCollection 属性的值。The index parameter is less than 0 or greater than the value of the Count property of the ListView.ListViewItemCollection.

注解

方法将项的属性设置为指定的键,因此可以通过其索引或键来检索该项。 Name InsertThe Insert method sets the Name property of the item to the specified key, so the item can be retrieved by its index or by key.

Insert(Int32, String, String, Int32)

创建一个具有指定的键、文本和图像的新项,并将该项插入到集合中指定索引处。Creates a new item with the specified key, text, and image, and inserts it in the collection at the specified index.

public:
 virtual System::Windows::Forms::ListViewItem ^ Insert(int index, System::String ^ key, System::String ^ text, int imageIndex);
public virtual System.Windows.Forms.ListViewItem Insert (int index, string key, string text, int imageIndex);
abstract member Insert : int * string * string * int -> System.Windows.Forms.ListViewItem
override this.Insert : int * string * string * int -> System.Windows.Forms.ListViewItem
Public Overridable Function Insert (index As Integer, key As String, text As String, imageIndex As Integer) As ListViewItem

参数

index
Int32

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

key
String

项的 NameThe Name of the item.

text
String

项的文本。The text of the item.

imageIndex
Int32

要为该项显示的图像的索引。The index of the image to display for the item.

返回

添加到集合中的 ListViewItemThe ListViewItem added to the collection.

异常

index 参数小于零或大于 CountListView.ListViewItemCollection 属性的值。The index parameter is less than 0 or greater than the value of the Count property of the ListView.ListViewItemCollection.

注解

方法将项的属性设置为指定的键,因此可以通过其索引或键来检索该项。 Name InsertThe Insert method sets the Name property of the item to the specified key, so the item can be retrieved by its index or by key.

Insert(Int32, String, String)

创建一个具有指定的文本和图像的新项,并将该项插入到集合中指定索引处。Creates a new item with the specified text and image and inserts it in the collection at the specified index.

public:
 System::Windows::Forms::ListViewItem ^ Insert(int index, System::String ^ text, System::String ^ imageKey);
public System.Windows.Forms.ListViewItem Insert (int index, string text, string imageKey);
member this.Insert : int * string * string -> System.Windows.Forms.ListViewItem
Public Function Insert (index As Integer, text As String, imageKey As String) As ListViewItem

参数

index
Int32

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

text
String

ListViewItem 的文本。The text of the ListViewItem.

imageKey
String

要为该项显示的图像的键。The key of the image to display for the item.

返回

添加到集合中的 ListViewItemThe ListViewItem added to the collection.

异常

index 参数小于零或大于 CountListView.ListViewItemCollection 属性的值。The index parameter is less than 0 or greater than the value of the Count property of the ListView.ListViewItemCollection.

Insert(Int32, ListViewItem)

将现有的 ListViewItem 插入到集合中的指定索引处。Inserts an existing ListViewItem into the collection at the specified index.

public:
 System::Windows::Forms::ListViewItem ^ Insert(int index, System::Windows::Forms::ListViewItem ^ item);
public System.Windows.Forms.ListViewItem Insert (int index, System.Windows.Forms.ListViewItem item);
member this.Insert : int * System.Windows.Forms.ListViewItem -> System.Windows.Forms.ListViewItem
Public Function Insert (index As Integer, item As ListViewItem) As ListViewItem

参数

index
Int32

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

item
ListViewItem

ListViewItem,表示要插入的项。The ListViewItem that represents the item to insert.

返回

已插入到集合中的 ListViewItemThe ListViewItem that was inserted into the collection.

异常

index 参数小于零或大于 CountListView.ListViewItemCollection 属性的值。The index parameter is less than 0 or greater than the value of the Count property of the ListView.ListViewItemCollection.

注解

此版本的Insert方法允许您在中ListView.ListViewItemCollection的特定位置ListViewItem插入现有。This version of the Insert method allows you to insert an existing ListViewItem at a specific position in the ListView.ListViewItemCollection.

备注

如果将SortOrder.None ListViewItemSorter属性设置为以外的值,或者如果设置了属性,则在插入项后会对该列表进行排序。 ListView.SortingIf the ListView.Sorting property is set to a value other than SortOrder.None or if the ListViewItemSorter property is set, the list is sorted after the item is inserted.

若要添加项而不在集合中指定要添加项的特定位置,请使用Add方法。To add an item without specifying a specific position in the collection to add the item, use the Add method. 如果要向集合中添加项的数组,请使用AddRange方法。If you want to add an array of items to the collection, use the AddRange method. 如果要在现有的项集合中插入新项,则可以使用此方法。You can use this method if you want to insert a new item into an existing collection of items.

另请参阅

Insert(Int32, String)

创建一个新项,并将其插入到集合中的指定索引处。Creates a new item and inserts it into the collection at the specified index.

public:
 System::Windows::Forms::ListViewItem ^ Insert(int index, System::String ^ text);
public System.Windows.Forms.ListViewItem Insert (int index, string text);
member this.Insert : int * string -> System.Windows.Forms.ListViewItem
Public Function Insert (index As Integer, text As String) As ListViewItem

参数

index
Int32

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

text
String

要为该项显示的文本。The text to display for the item.

返回

已插入到集合中的 ListViewItemThe ListViewItem that was inserted into the collection.

异常

index 参数小于零或大于 CountListView.ListViewItemCollection 属性的值。The index parameter is less than 0 or greater than the value of the Count property of the ListView.ListViewItemCollection.

注解

此版本的Insert方法允许您在ListView.ListViewItemCollection中的特定位置插入一个新项。This version of the Insert method allows you to insert a new item at a specific position in the ListView.ListViewItemCollection. text参数中指定的文本用于创建新ListViewItem的,然后将其插入到指定位置的ListView.ListViewItemCollection中。The text specified in the text parameter is used to create a new ListViewItem that is then inserted into the ListView.ListViewItemCollection at the specified location.

备注

如果将SortOrder.None ListViewItemSorter属性设置为以外的值,或者如果设置了属性,则在插入项后会对该列表进行排序。 ListView.SortingIf the ListView.Sorting property is set to a value other than SortOrder.None or if the ListViewItemSorter property is set, the list is sorted after the item is inserted.

若要添加项而不指定集合中的特定位置,请使用Add方法。To add an item without specifying a specific position in the collection, use the Add method. 如果要向集合中添加项的数组,请使用AddRange方法。If you want to add an array of items to the collection, use the AddRange method. 如果要在现有的项集合中插入新项,则可以使用此方法。You can use this method if you want to insert a new item into an existing collection of items.

另请参阅

Insert(Int32, String, Int32)

创建具有指定图像索引的新项,并将其插入到集合中的指定索引处。Creates a new item with the specified image index and inserts it into the collection at the specified index.

public:
 System::Windows::Forms::ListViewItem ^ Insert(int index, System::String ^ text, int imageIndex);
public System.Windows.Forms.ListViewItem Insert (int index, string text, int imageIndex);
member this.Insert : int * string * int -> System.Windows.Forms.ListViewItem
Public Function Insert (index As Integer, text As String, imageIndex As Integer) As ListViewItem

参数

index
Int32

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

text
String

要为该项显示的文本。The text to display for the item.

imageIndex
Int32

要为该项显示的图像的索引。The index of the image to display for the item.

返回

已插入到集合中的 ListViewItemThe ListViewItem that was inserted into the collection.

异常

index 参数小于零或大于 CountListView.ListViewItemCollection 属性的值。The index parameter is less than 0 or greater than the value of the Count property of the ListView.ListViewItemCollection.

注解

此版本的Insert方法允许您在ListView.ListViewItemCollection中的特定位置插入一个新项。This version of the Insert method allows you to insert a new item at a specific position in the ListView.ListViewItemCollection. text参数中指定的文本用于创建新ListViewItem的,然后将其插入到指定位置的ListView.ListViewItemCollection中。The text specified in the text parameter is used to create a new ListViewItem that is then inserted into the ListView.ListViewItemCollection at the specified location.

备注

如果将SortOrder.None ListViewItemSorter属性设置为以外的值,或者如果设置了属性,则在插入项后会对该列表进行排序。 ListView.SortingIf the ListView.Sorting property is set to a value other than SortOrder.None or if the ListViewItemSorter property is set, the list is sorted after the item is inserted.

你还可以使用此Insert版本的方法通过将ImageList分配给ListView.LargeImageListListView.SmallImageList属性imageIndex的索引传递给参数来为项指定一个图像。You can also use this version of the Insert method to specify an image for the item by passing the index of the ImageList assigned to the ListView.LargeImageList and ListView.SmallImageList properties to the imageIndex parameter. (通常情况下ListView.LargeImageListListView.SmallImageList和属性使用相同的索引位置来显示相关图像。)如果您不希望为该项指定图像索引,请使用接受字符串作为参数的Insert方法的另一个版本。(Typically, the ListView.LargeImageList and ListView.SmallImageList properties use the same index positions to display related images.) If you do not want to specify an image index for the item, use the other version of the Insert method that accepts a string as a parameter.

若要添加项而不指定集合中的特定位置,请使用Add方法。To add an item without specifying a specific position in the collection, use the Add method. 如果要向集合中添加项的数组,请使用AddRange方法。If you want to add an array of items to the collection, use the AddRange method.

另请参阅

适用于