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)

将现有的 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)

用指定的文本创建一个项并将该项添加到集合中。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);
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

ListViewItem

已添加到集合的 ListViewItemThe ListViewItem that was added to the collection.

Remarks

您可以使用此版本的 Add 方法创建要添加到 ListView 控件的新 ListViewItemYou can use this version of the Add method to create a new ListViewItem to add to a ListView control. 添加到控件中的新 ListViewItem 的文本基于 text 参数。The text of the new ListViewItem added to the control is based on the text parameter. 如果要为项指定图像,请使用接受图像索引作为参数的 Add 方法的版本。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. 如果你有想要添加到集合中的现有 ListViewItem,请使用接受 ListViewItem 作为参数的 Add 方法的版本。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.

如果 ListView.Sorting 属性设置为 SortOrder.None 以外的值,或者如果设置了 ListViewItemSorter 属性,则在添加项后会对该列表进行排序。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. 如果列表未排序,则可以使用 Insert 方法将某个项插入到 ListView 中的特定位置。If the list is not sorted, you can use the Insert method to insert an item into the ListView at a specific position. 若要在一个操作中将一组项添加到控件,请使用 AddRange 方法。To add a set of items to the control in a single operation, use the AddRange method. 如果要使用 Add 方法将大量的项添加到控件,请使用 BeginUpdateEndUpdate 方法,以防止 ListView 重新绘制,直到添加所有项。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. ListView添加项时,先对项进行排序并添加新项会更有效。When adding items to a ListView, it is more efficient to sort the items first and then add new items.

See also

Add(ListViewItem)

将现有的 ListViewItem 添加到集合中。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

要添加到集合的 ListViewItemThe ListViewItem to add to the collection.

Returns

ListViewItem

已添加到集合的 ListViewItemThe ListViewItem that was added to the collection.

Remarks

您可以使用此版本的 Add 方法将现有 ListViewItem 添加到集合中。You can use this version of the Add method to add an existing ListViewItem to the collection. 此版本的 Add 方法通常用于重用其他 ListView 控件中的项,或者,如果 ListViewItem 是在将其添加到集合之前手动创建的,则为。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. 如果要创建新的 ListViewItem 而不是使用现有项,请使用 Add 方法的其他版本。If you want to create a new ListViewItem instead of using an existing item, use the other versions of the Add method.

如果 ListView.Sorting 属性设置为 SortOrder.None 以外的值,或者如果设置了 ListViewItemSorter 属性,则在添加项后会对该列表进行排序。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. 如果列表未排序,则可以使用 Insert 方法将某个项插入到 ListView 中的特定位置。If the list is not sorted, you can use the Insert method to insert an item into the ListView at a specific position. 若要在一个操作中将一组项添加到控件,请使用 AddRange 方法。To add a set of items to the control in a single operation, use the AddRange method. 如果要使用 Add 方法将大量的项添加到控件,请使用 BeginUpdateEndUpdate 方法,以防止 ListView 重新绘制,直到添加所有项。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. ListView添加项时,先对项进行排序并添加新项会更有效。When adding items to a ListView, it is more efficient to sort the items first and then add new items.

此版本的 Add 方法还用于将 ListViewItem 分配给 ListViewGroupThis version of the Add method is also used to assign a ListViewItem to a ListViewGroup.

See also

Add(String, Int32)

用指定的文本和图像创建一个项并将该项添加到集合中。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);
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

ListViewItem

已添加到集合的 ListViewItemThe ListViewItem that was added to the collection.

Remarks

您可以使用此版本的 Add 方法创建要添加到 ListView 控件的新 ListViewItemYou can use this version of the Add method to create a new ListViewItem to add to the ListView control. 添加到控件中的新 ListViewItem 的文本基于 text 参数。The text of the new ListViewItem added to the control is based on the text parameter. 还可以通过将分配给 ListView.LargeImageListImageList 的索引和 ListView.SmallImageList 属性传递给 imageIndex 参数,为项指定一个图像。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. (通常情况下,ListView.LargeImageListListView.SmallImageList 属性使用相同的索引位置来显示相关图像。)如果不想为项指定图像索引,请使用仅接受字符串作为参数的 Add 方法的版本。(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. 如果你有想要添加到集合中的现有 ListViewItem,请使用接受 ListViewItem 作为参数的 Add 方法的版本。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.

如果 ListView.Sorting 属性设置为 SortOrder.None 以外的值,或者如果设置了 ListViewItemSorter 属性,则在添加项后会对该列表进行排序。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. 如果列表未排序,则可以使用 Insert 方法将某个项插入到 ListView 中的特定位置。If the list is not sorted, you can use the Insert method to insert an item into the ListView at a specific position. 若要在一个操作中将一组项添加到控件,请使用 AddRange 方法。To add a set of items to the control in a single operation, use the AddRange method. 如果要使用 Add 方法将大量的项添加到控件,请使用 BeginUpdateEndUpdate 方法,以防止 ListView 重新绘制,直到添加所有项。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. ListView添加项时,先对项进行排序并添加新项会更有效。When adding items to a ListView, it is more efficient to sort the items first and then add new items.

See also

Add(String, String)

用指定的文本和图像创建一个项并将该项添加到集合中。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);
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

ListViewItem

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

Remarks

如果 ListView 已排序,则按正确排序的顺序添加项;否则,会将其添加到集合的末尾。If the ListView is sorted, the item is added in the correctly sorted order; otherwise, it is added to the end of the collection.

Add(String, String, Int32)

用指定的键、文本和图像创建一个项并将该项添加到集合中。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);
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

ListViewItem

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

Exceptions

包含 ListView 处于虚拟模式下。The containing ListView is in virtual mode.

Remarks

如果 ListView 已排序,则按正确排序的顺序添加项;否则,会将其添加到集合的末尾。If the ListView is sorted, the item is added in the correctly sorted order; otherwise, it is added to the end of the collection. Name 属性对应于 ListView.ListViewItemCollectionListViewItem 的键。The Name property corresponds to the key for a ListViewItem in the ListView.ListViewItemCollection.

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

Add(String, String, String)

用指定的键、文本和图像创建一个项并将该项添加到集合中。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);
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

ListViewItem

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

Remarks

Name 属性对应于 ListView.ListViewItemCollectionListViewItem 的键。The Name property corresponds to the key for a ListViewItem in the ListView.ListViewItemCollection.

如果 ListView 已排序,则按正确排序的顺序添加项;否则,会将其添加到集合的末尾。If the ListView is sorted, the item is added in the correctly sorted order; otherwise, it is added to the end of the collection. Add 方法将项的 Name 属性设置为指定的键,因此可以通过其索引或键来检索该项。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