ListView.ListViewItemCollection.Add ListView.ListViewItemCollection.Add ListView.ListViewItemCollection.Add ListView.ListViewItemCollection.Add Method

定义

将项添至项的集合中。Adds an item to the collection of items.

重载

Add(String) Add(String) Add(String) Add(String)

用指定的文本创建一个项并将该项添加到集合中。Creates an item with the specified text and adds it to the collection.

Add(ListViewItem) Add(ListViewItem) Add(ListViewItem) Add(ListViewItem)

将现有的 ListViewItem 添加到集合中。Adds an existing ListViewItem to the collection.

Add(String, Int32) Add(String, Int32) Add(String, Int32) Add(String, Int32)

用指定的文本和图像创建一个项并将该项添加到集合中。Creates an item with the specified text and image and adds it to the collection.

Add(String, String) Add(String, String) Add(String, String) Add(String, String)

用指定的文本和图像创建一个项并将该项添加到集合中。Creates an item with the specified text and image and adds it to the collection.

Add(String, String, Int32) Add(String, String, Int32) Add(String, String, Int32) 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) Add(String, String, String) Add(String, String, String) Add(String, String, String)

用指定的键、文本和图像创建一个项并将该项添加到集合中。Creates an item with the specified key, text, and image, and adds it to the collection.

Add(String) Add(String) Add(String) 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

参数

text
String String String String

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

返回

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

注解

您可以使用此版本的Add方法创建一个新ListViewItem的以添加到ListView控件中。You 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.

如果将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 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方法向控件添加大量的项,请BeginUpdate使用ListViewEndUpdate方法,以防止在添加所有项之前进行重新绘制。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) Add(ListViewItem) Add(ListViewItem) 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

参数

value
ListViewItem ListViewItem ListViewItem ListViewItem

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

返回

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

注解

您可以使用此版本的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.

如果将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 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方法向控件添加大量的项,请BeginUpdate使用ListViewEndUpdate方法,以防止在添加所有项之前进行重新绘制。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.

另请参阅

Add(String, Int32) Add(String, Int32) Add(String, Int32) 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

参数

text
String String String String

项的文本。The text of the item.

imageIndex
Int32 Int32 Int32 Int32

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

返回

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

注解

您可以使用此版本的Add方法创建一个新ListViewItem的以添加到ListView控件中。You 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. 还可以通过ImageList将分配ListView.LargeImageList给和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.

如果将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 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方法向控件添加大量的项,请BeginUpdate使用ListViewEndUpdate方法,以防止在添加所有项之前进行重新绘制。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(String, String) Add(String, String) Add(String, String) 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

参数

text
String String String String

项的文本。The text of the item.

imageKey
String String String String

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

返回

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

注解

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) Add(String, String, Int32) Add(String, String, Int32) 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

参数

key
String String String String

项的名称。The name of the item.

text
String String String String

项的文本。The text of the item.

imageIndex
Int32 Int32 Int32 Int32

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

返回

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

异常

注解

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. 属性对应于中ListViewItem ListView.ListViewItemCollection的的键。 NameThe 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) Add(String, String, String) Add(String, String, String) 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

参数

key
String String String String

项的名称。The name of the item.

text
String String String String

项的文本。The text of the item.

imageKey
String String String String

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

返回

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

注解

属性对应于中ListViewItem ListView.ListViewItemCollection的的键。 NameThe 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. 方法将项的属性设置为指定的键,因此可以通过其索引或键来检索该项。 Name AddThe 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.

适用于