Edit

Share via


ListView.ListViewItemCollection.Insert Method

Definition

Inserts an item into the collection at the specified index.

Overloads

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)

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);
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

Parameters

index
Int32

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

key
String

The Name of the item.

text
String

The text of the item.

imageKey
String

The key of the image to display for the item.

Returns

The ListViewItem added to the collection.

Exceptions

The index parameter is less than 0 or greater than the value of the Count property of the ListView.ListViewItemCollection.

Remarks

The 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.

Applies to

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);
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

Parameters

index
Int32

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

key
String

The Name of the item.

text
String

The text of the item.

imageIndex
Int32

The index of the image to display for the item.

Returns

The ListViewItem added to the collection.

Exceptions

The index parameter is less than 0 or greater than the value of the Count property of the ListView.ListViewItemCollection.

Remarks

The 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.

Applies to

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);
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

Parameters

index
Int32

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

text
String

The text of the ListViewItem.

imageKey
String

The key of the image to display for the item.

Returns

The ListViewItem added to the collection.

Exceptions

The index parameter is less than 0 or greater than the value of the Count property of the ListView.ListViewItemCollection.

Applies to

Insert(Int32, 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

Parameters

index
Int32

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

item
ListViewItem

The ListViewItem that represents the item to insert.

Returns

The ListViewItem that was inserted into the collection.

Exceptions

The index parameter is less than 0 or greater than the value of the Count property of the ListView.ListViewItemCollection.

Remarks

This version of the Insert method allows you to insert an existing ListViewItem at a specific position in the ListView.ListViewItemCollection.

Note

If 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.

To add an item without specifying a specific position in the collection to add the item, use the Add method. 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.

See also

Applies to

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);
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

Parameters

index
Int32

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

text
String

The text to display for the item.

Returns

The ListViewItem that was inserted into the collection.

Exceptions

The index parameter is less than 0 or greater than the value of the Count property of the ListView.ListViewItemCollection.

Remarks

This version of the Insert method allows you to insert a new item at a specific position in the 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.

Note

If 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.

To add an item without specifying a specific position in the collection, use the Add method. 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.

See also

Applies to

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);
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

Parameters

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.

Returns

The ListViewItem that was inserted into the collection.

Exceptions

The index parameter is less than 0 or greater than the value of the Count property of the ListView.ListViewItemCollection.

Remarks

This version of the Insert method allows you to insert a new item at a specific position in the 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.

Note

If 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.

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. (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.

To add an item without specifying a specific position in the collection, use the Add method. If you want to add an array of items to the collection, use the AddRange method.

See also

Applies to