Editar

Compartir a través de


ListView.ListViewItemCollection.Add Method

Definition

Adds an item to the collection of items.

Overloads

Add(String)

Creates an item with the specified text and adds it to the collection.

Add(ListViewItem)

Adds an existing ListViewItem to the collection.

Add(String, Int32)

Creates an item with the specified text and image and adds it to the collection.

Add(String, String)

Creates an item with the specified text and image and adds it to the collection.

Add(String, String, Int32)

Creates an item with the specified key, text, and image and adds an item to the collection.

Add(String, String, String)

Creates an item with the specified key, text, and image, and adds it to the collection.

Add(String)

Source:
ListView.ListViewItemCollection.cs
Source:
ListView.ListViewItemCollection.cs
Source:
ListView.ListViewItemCollection.cs

Creates an item with the specified text and adds it to the collection.

public:
 virtual System::Windows::Forms::ListViewItem ^ Add(System::String ^ text);
public virtual System.Windows.Forms.ListViewItem Add (string text);
public virtual System.Windows.Forms.ListViewItem Add (string? text);
abstract member Add : string -> System.Windows.Forms.ListViewItem
override this.Add : string -> System.Windows.Forms.ListViewItem
Public Overridable Function Add (text As String) As ListViewItem

Parameters

text
String

The text to display for the item.

Returns

The ListViewItem that was added to the collection.

Remarks

You can use this version of the Add method to create a new ListViewItem to add to a ListView control. The text of the new ListViewItem added to the control is based on the text parameter. If you want to specify an image for the item, use the version of the Add method that accepts an image index as a parameter. If you have an existing ListViewItem that you want to add to the collection, use the version of the Add method that accepts a ListViewItem as its parameter.

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 added. Otherwise, the item is inserted at the end of the list. If the list is not sorted, you can use the Insert method to insert an item into the ListView at a specific position. To add a set of items to the control in a single operation, use the AddRange method. If you want to use the Add method to add a large number of items to the control, use the BeginUpdate and EndUpdate methods to prevent the ListView from repainting until all items are added. When adding items to a ListView, it is more efficient to sort the items first and then add new items.

See also

Applies to

Add(ListViewItem)

Source:
ListView.ListViewItemCollection.cs
Source:
ListView.ListViewItemCollection.cs
Source:
ListView.ListViewItemCollection.cs

Adds an existing ListViewItem to the collection.

public:
 virtual System::Windows::Forms::ListViewItem ^ Add(System::Windows::Forms::ListViewItem ^ value);
public virtual System.Windows.Forms.ListViewItem Add (System.Windows.Forms.ListViewItem value);
abstract member Add : System.Windows.Forms.ListViewItem -> System.Windows.Forms.ListViewItem
override this.Add : System.Windows.Forms.ListViewItem -> System.Windows.Forms.ListViewItem
Public Overridable Function Add (value As ListViewItem) As ListViewItem

Parameters

value
ListViewItem

The ListViewItem to add to the collection.

Returns

The ListViewItem that was added to the collection.

Remarks

You can use this version of the Add method to add an existing ListViewItem to the collection. This version of the Add method is typically used to reuse items from other ListView controls or if the ListViewItem was created manually before adding it to the collection. If you want to create a new ListViewItem instead of using an existing item, use the other versions of the Add method.

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 added. Otherwise, the item is inserted at the end of the list. If the list is not sorted, you can use the Insert method to insert an item into the ListView at a specific position. To add a set of items to the control in a single operation, use the AddRange method. If you want to use the Add method to add a large number of items to the control, use the BeginUpdate and EndUpdate methods to prevent the ListView from repainting until all items are added. When adding items to a ListView, it is more efficient to sort the items first and then add new items.

This version of the Add method is also used to assign a ListViewItem to a ListViewGroup.

See also

Applies to

Add(String, Int32)

Source:
ListView.ListViewItemCollection.cs
Source:
ListView.ListViewItemCollection.cs
Source:
ListView.ListViewItemCollection.cs

Creates an item with the specified text and image and adds it to the collection.

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

Parameters

text
String

The text of the item.

imageIndex
Int32

The index of the image to display for the item.

Returns

The ListViewItem that was added to the collection.

Remarks

You can use this version of the Add method to create a new ListViewItem to add to the ListView control. The text of the new ListViewItem added to the control is based on the text parameter. You can also 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 version of the Add method that accepts only a string as a parameter. If you have an existing ListViewItem that you want to add to the collection, use the version of the Add method that accepts a ListViewItem as its parameter.

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 added. Otherwise, the item is inserted at the end of the list. If the list is not sorted, you can use the Insert method to insert an item into the ListView at a specific position. To add a set of items to the control in a single operation, use the AddRange method. If you want to use the Add method to add a large number of items to the control, use the BeginUpdate and EndUpdate methods to prevent the ListView from repainting until all items are added. When adding items to a ListView, it is more efficient to sort the items first and then add new items.

See also

Applies to

Add(String, String)

Source:
ListView.ListViewItemCollection.cs
Source:
ListView.ListViewItemCollection.cs
Source:
ListView.ListViewItemCollection.cs

Creates an item with the specified text and image and adds it to the collection.

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

Parameters

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.

Remarks

If the ListView is sorted, the item is added in the correctly sorted order; otherwise, it is added to the end of the collection.

Applies to

Add(String, String, Int32)

Source:
ListView.ListViewItemCollection.cs
Source:
ListView.ListViewItemCollection.cs
Source:
ListView.ListViewItemCollection.cs

Creates an item with the specified key, text, and image and adds an item to the collection.

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

Parameters

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 containing ListView is in virtual mode.

Remarks

If the ListView is sorted, the item is added in the correctly sorted order; otherwise, it is added to the end of the collection. The Name property corresponds to the key for a ListViewItem in the ListView.ListViewItemCollection.

The Add method sets the Name property to the specified key, so the item can be retrieved by its index or by key.

Applies to

Add(String, String, String)

Source:
ListView.ListViewItemCollection.cs
Source:
ListView.ListViewItemCollection.cs
Source:
ListView.ListViewItemCollection.cs

Creates an item with the specified key, text, and image, and adds it to the collection.

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

Parameters

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.

Remarks

The Name property corresponds to the key for a ListViewItem in the ListView.ListViewItemCollection.

If the ListView is sorted, the item is added in the correctly sorted order; otherwise, it is added to the end of the collection. The Add 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