ListView.ListViewItemCollection.Add Method (String, Int32)
Creates an item with the specified text and image and adds it to the collection.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
- Type: System.String
The text of the item.
- Type: System.Int32
The index of the image to display for the item.
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.
Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.