ListViewItem Constructors

Definition

Initializes a new instance of the ListViewItem class.

Overloads

ListViewItem()

Initializes a new instance of the ListViewItem class with default values.

ListViewItem(String[], String, Color, Color, Font, ListViewGroup)

Initializes a new instance of the ListViewItem class with the subitems containing the specified text, image, colors, font, and group.

ListViewItem(String[], Int32, Color, Color, Font, ListViewGroup)

Initializes a new instance of the ListViewItem class with the image index position of the item's icon; the foreground color, background color, and font of the item; and an array of strings representing subitems. Assigns the item to the specified group.

ListViewItem(String[], String, Color, Color, Font)

Initializes a new instance of the ListViewItem class with the subitems containing the specified text, image, colors, and font.

ListViewItem(String[], Int32, Color, Color, Font)

Initializes a new instance of the ListViewItem class with the image index position of the item's icon; the foreground color, background color, and font of the item; and an array of strings representing subitems.

ListViewItem(ListViewItem+ListViewSubItem[], String, ListViewGroup)

Initializes a new instance of the ListViewItem class with the specified subitems, image, and group.

ListViewItem(ListViewItem+ListViewSubItem[], Int32, ListViewGroup)

Initializes a new instance of the ListViewItem class with the image index position of the item's icon and an array of ListViewItem.ListViewSubItem objects, and assigns the item to the specified group.

ListViewItem(String[], String, ListViewGroup)

Initializes a new instance of the ListViewItem class with subitems containing the specified text, image, and group.

ListViewItem(String[], Int32, ListViewGroup)

Initializes a new instance of the ListViewItem class with the image index position of the item's icon and an array of strings representing subitems, and assigns the item to the specified group.

ListViewItem(String, String, ListViewGroup)

Initializes a new instance of the ListViewItem class with the specified text, image, and group.

ListViewItem(ListViewItem+ListViewSubItem[], String)

Initializes a new instance of the ListViewItem class with the specified subitems and image.

ListViewItem(String, Int32, ListViewGroup)

Initializes a new instance of the ListViewItem class with the specified item text and the image index position of the item's icon, and assigns the item to the specified group.

ListViewItem(String[], ListViewGroup)

Initializes a new instance of the ListViewItem class with an array of strings representing subitems, and assigns the item to the specified group.

ListViewItem(String[], String)

Initializes a new instance of the ListViewItem class with the specified item and subitem text and image.

ListViewItem(String[], Int32)

Initializes a new instance of the ListViewItem class with the image index position of the item's icon and an array of strings representing subitems.

ListViewItem(String, ListViewGroup)

Initializes a new instance of the ListViewItem class with the specified item text and assigns it to the specified group.

ListViewItem(String, String)

Initializes a new instance of the ListViewItem class with the specified text and image.

ListViewItem(String, Int32)

Initializes a new instance of the ListViewItem class with the specified item text and the image index position of the item's icon.

ListViewItem(SerializationInfo, StreamingContext)

Initializes a new instance of the ListViewItem class with the specified serialization information and streaming context.

ListViewItem(ListViewGroup)

Initializes a new instance of the ListViewItem class and assigns it to the specified group.

ListViewItem(String[])

Initializes a new instance of the ListViewItem class with an array of strings representing subitems.

ListViewItem(String)

Initializes a new instance of the ListViewItem class with the specified item text.

ListViewItem(ListViewItem+ListViewSubItem[], Int32)

Initializes a new instance of the ListViewItem class with the image index position of the item's icon and an array of ListViewItem.ListViewSubItem objects.

ListViewItem()

Source:
ListViewItem.cs
Source:
ListViewItem.cs
Source:
ListViewItem.cs

Initializes a new instance of the ListViewItem class with default values.

C#
public ListViewItem();

Examples

The following code example creates a ListView control with three ListViewItem objects specified and three ListViewItem.ListViewSubItem objects specified for each item. The example also creates ColumnHeader objects to display the subitems in details view. Two ImageList objects are also created in the code example to provide images for the ListViewItem objects. These ImageList objects are added to the LargeImageList and SmallImageList properties. The example uses the following properties in creating the ListView control:

You need to add the code to a Form and call the method created in the example from the constructor or another method on the form. The example requires that images named MySmallImage1, MySmallImage2, MyLargeImage1, and MyLargeImage2 are located in the root directory of drive C.

C#
private void CreateMyListView()
{
    // Create a new ListView control.
    ListView listView1 = new ListView();
    listView1.Bounds = new Rectangle(new Point(10,10), new Size(300,200));

    // Set the view to show details.
    listView1.View = View.Details;
    // Allow the user to edit item text.
    listView1.LabelEdit = true;
    // Allow the user to rearrange columns.
    listView1.AllowColumnReorder = true;
    // Display check boxes.
    listView1.CheckBoxes = true;
    // Select the item and subitems when selection is made.
    listView1.FullRowSelect = true;
    // Display grid lines.
    listView1.GridLines = true;
    // Sort the items in the list in ascending order.
    listView1.Sorting = SortOrder.Ascending;
                
    // Create three items and three sets of subitems for each item.
    ListViewItem item1 = new ListViewItem("item1",0);
    // Place a check mark next to the item.
    item1.Checked = true;
    item1.SubItems.Add("1");
    item1.SubItems.Add("2");
    item1.SubItems.Add("3");
    ListViewItem item2 = new ListViewItem("item2",1);
    item2.SubItems.Add("4");
    item2.SubItems.Add("5");
    item2.SubItems.Add("6");
    ListViewItem item3 = new ListViewItem("item3",0);
    // Place a check mark next to the item.
    item3.Checked = true;
    item3.SubItems.Add("7");
    item3.SubItems.Add("8");
    item3.SubItems.Add("9");

    // Create columns for the items and subitems.
    // Width of -2 indicates auto-size.
    listView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left);
    listView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left);
    listView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left);
    listView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center);

    //Add the items to the ListView.
    listView1.Items.AddRange(new ListViewItem[]{item1,item2,item3});

    // Create two ImageList objects.
    ImageList imageListSmall = new ImageList();
    ImageList imageListLarge = new ImageList();

    // Initialize the ImageList objects with bitmaps.
    imageListSmall.Images.Add(Bitmap.FromFile("C:\\MySmallImage1.bmp"));
    imageListSmall.Images.Add(Bitmap.FromFile("C:\\MySmallImage2.bmp"));
    imageListLarge.Images.Add(Bitmap.FromFile("C:\\MyLargeImage1.bmp"));
    imageListLarge.Images.Add(Bitmap.FromFile("C:\\MyLargeImage2.bmp"));

    //Assign the ImageList objects to the ListView.
    listView1.LargeImageList = imageListLarge;
    listView1.SmallImageList = imageListSmall;

    // Add the ListView to the control collection.
    this.Controls.Add(listView1);
}

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

ListViewItem(String[], String, Color, Color, Font, ListViewGroup)

Source:
ListViewItem.cs
Source:
ListViewItem.cs
Source:
ListViewItem.cs

Initializes a new instance of the ListViewItem class with the subitems containing the specified text, image, colors, font, and group.

C#
public ListViewItem(string[] items, string imageKey, System.Drawing.Color foreColor, System.Drawing.Color backColor, System.Drawing.Font font, System.Windows.Forms.ListViewGroup group);
C#
public ListViewItem(string[]? items, string? imageKey, System.Drawing.Color foreColor, System.Drawing.Color backColor, System.Drawing.Font? font, System.Windows.Forms.ListViewGroup? group);

Parameters

items
String[]

An array of strings that represents the text of the subitems for the ListViewItem.

imageKey
String

The name of the image within the ImageList of the owning ListView to display in the item.

foreColor
Color

A Color that represents the foreground color of the item.

backColor
Color

A Color that represents the background color of the item.

font
Font

A Font to apply to the item text.

group
ListViewGroup

The ListViewGroup to assign the item to.

Remarks

This version of the constructor allows you to specify the group to which an item belongs.

The imageKey parameter specifies an image in the ImageList associated with the owning ListView control, which can be accessed with the ImageList property.

Note

ListView groups are only available on Windows XP and the Windows Server 2003 family (Windows XP Home Edition, Windows XP Professional, Windows Server 2003). For more information, see the ListViewGroup overview topic.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

ListViewItem(String[], Int32, Color, Color, Font, ListViewGroup)

Source:
ListViewItem.cs
Source:
ListViewItem.cs
Source:
ListViewItem.cs

Initializes a new instance of the ListViewItem class with the image index position of the item's icon; the foreground color, background color, and font of the item; and an array of strings representing subitems. Assigns the item to the specified group.

C#
public ListViewItem(string[] items, int imageIndex, System.Drawing.Color foreColor, System.Drawing.Color backColor, System.Drawing.Font font, System.Windows.Forms.ListViewGroup group);
C#
public ListViewItem(string[]? items, int imageIndex, System.Drawing.Color foreColor, System.Drawing.Color backColor, System.Drawing.Font? font, System.Windows.Forms.ListViewGroup? group);

Parameters

items
String[]

An array of strings that represent the subitems of the new item.

imageIndex
Int32

The zero-based index of the image within the ImageList associated with the ListView that contains the item.

foreColor
Color

A Color that represents the foreground color of the item.

backColor
Color

A Color that represents the background color of the item.

font
Font

A Font that represents the font to display the item's text in.

group
ListViewGroup

The ListViewGroup to assign the item to.

Remarks

This version of the constructor allows you to specify the group to which an item belongs.

Note

ListView groups are only available on Windows XP and the Windows Server 2003 family (Windows XP Home Edition, Windows XP Professional, Windows Server 2003). For more information, see the ListViewGroup overview topic.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

ListViewItem(String[], String, Color, Color, Font)

Source:
ListViewItem.cs
Source:
ListViewItem.cs
Source:
ListViewItem.cs

Initializes a new instance of the ListViewItem class with the subitems containing the specified text, image, colors, and font.

C#
public ListViewItem(string[] items, string imageKey, System.Drawing.Color foreColor, System.Drawing.Color backColor, System.Drawing.Font font);
C#
public ListViewItem(string[]? items, string? imageKey, System.Drawing.Color foreColor, System.Drawing.Color backColor, System.Drawing.Font? font);

Parameters

items
String[]

An array of strings that represent the text of the subitems for the ListViewItem.

imageKey
String

The name of the image within the ImageList of the owning ListView to display in the item.

foreColor
Color

A Color that represents the foreground color of the item.

backColor
Color

A Color that represents the background color of the item.

font
Font

A Font to apply to the item text.

Remarks

The imageKey parameter specifies an image in the ImageList associated with the owning ListView control, which can be accessed with the ImageList property.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

ListViewItem(String[], Int32, Color, Color, Font)

Source:
ListViewItem.cs
Source:
ListViewItem.cs
Source:
ListViewItem.cs

Initializes a new instance of the ListViewItem class with the image index position of the item's icon; the foreground color, background color, and font of the item; and an array of strings representing subitems.

C#
public ListViewItem(string[] items, int imageIndex, System.Drawing.Color foreColor, System.Drawing.Color backColor, System.Drawing.Font font);
C#
public ListViewItem(string[]? items, int imageIndex, System.Drawing.Color foreColor, System.Drawing.Color backColor, System.Drawing.Font? font);

Parameters

items
String[]

An array of strings that represent the subitems of the new item.

imageIndex
Int32

The zero-based index of the image within the ImageList associated with the ListView that contains the item.

foreColor
Color

A Color that represents the foreground color of the item.

backColor
Color

A Color that represents the background color of the item.

font
Font

A Font that represents the font to display the item's text in.

Examples

The following code example creates a form that contains a ListView control that manually sorts items when a column in the ListView control is clicked. The example defines a class called ListViewItemComparer that implements the System.Collections.IComparer interface that performs the ListViewItem comparison. The example creates an instance of ListViewItemComparer and uses it to set the ListViewItemSorter property of the ListView control. The Sort method call in the ColumnClick event handler uses the methods defined in ListViewItemComparer to perform the sort of items, based on the column that is clicked.

C#
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Collections;

namespace ListViewSortFormNamespace
{

    public class ListViewSortForm : Form
    {
        private ListView listView1;
       
        public ListViewSortForm()
        {
            // Create ListView items to add to the control.
            ListViewItem listViewItem1 = new ListViewItem(new string[] {"Banana","a","b","c"}, -1, Color.Empty, Color.Yellow, null);
            ListViewItem listViewItem2 = new ListViewItem(new string[] {"Cherry","v","g","t"}, -1, Color.Empty, Color.Red, new Font("Microsoft Sans Serif", 8.25F, FontStyle.Regular, GraphicsUnit.Point, ((System.Byte)(0))));
            ListViewItem listViewItem3 = new ListViewItem(new string[] {"Apple","h","j","n"}, -1, Color.Empty, Color.Lime, null);
            ListViewItem listViewItem4 = new ListViewItem(new string[] {"Pear","y","u","i"}, -1, Color.Empty, Color.FromArgb(((System.Byte)(192)), ((System.Byte)(128)), ((System.Byte)(156))), null);
     
            //Initialize the ListView control and add columns to it.
            this.listView1 = new ListView();

            // Set the initial sorting type for the ListView.
            this.listView1.Sorting = SortOrder.None;
            // Disable automatic sorting to enable manual sorting.
            this.listView1.View = View.Details;
            // Add columns and set their text.
            this.listView1.Columns.Add(new ColumnHeader());
            this.listView1.Columns[0].Text = "Column 1";
            this.listView1.Columns[0].Width = 100;
            listView1.Columns.Add(new ColumnHeader());
            listView1.Columns[1].Text = "Column 2";
            listView1.Columns.Add(new ColumnHeader());
            listView1.Columns[2].Text = "Column 3";
            listView1.Columns.Add(new ColumnHeader());
            listView1.Columns[3].Text = "Column 4";
            // Suspend control logic until form is done configuring form.
            this.SuspendLayout();
            // Add Items to the ListView control.
            this.listView1.Items.AddRange(new ListViewItem[] {listViewItem1,
                listViewItem2,
                listViewItem3,
                listViewItem4});
            // Set the location and size of the ListView control.
            this.listView1.Location = new Point(10, 10);
            this.listView1.Name = "listView1";
            this.listView1.Size = new Size(300, 100);
            this.listView1.TabIndex = 0;
            // Enable editing of the items in the ListView.
            this.listView1.LabelEdit = true;
            // Connect the ListView.ColumnClick event to the ColumnClick event handler.
            this.listView1.ColumnClick += new ColumnClickEventHandler(ColumnClick);
            
            // Initialize the form.
            this.ClientSize = new Size(400, 400);
            this.Controls.AddRange(new Control[] {this.listView1});
            this.Name = "ListViewSortForm";
            this.Text = "Sorted ListView Control";
            // Resume layout of the form.
            this.ResumeLayout(false);
        }

        // ColumnClick event handler.
        private void ColumnClick(object o, ColumnClickEventArgs e)
        {
            // Set the ListViewItemSorter property to a new ListViewItemComparer 
            // object. Setting this property immediately sorts the 
            // ListView using the ListViewItemComparer object.
            this.listView1.ListViewItemSorter = new ListViewItemComparer(e.Column);
        }

        [System.STAThreadAttribute()]
        public static void Main()
        {
            Application.Run(new ListViewSortForm());
        }
    }

    // Implements the manual sorting of items by columns.
    class ListViewItemComparer : IComparer
    {
        private int col;
        public ListViewItemComparer()
        {
            col = 0;
        }
        public ListViewItemComparer(int column)
        {
            col = column;
        }
        public int Compare(object x, object y)
        {
            return String.Compare(((ListViewItem)x).SubItems[col].Text, ((ListViewItem)y).SubItems[col].Text);
        }
    }
}

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

ListViewItem(ListViewItem+ListViewSubItem[], String, ListViewGroup)

Source:
ListViewItem.cs
Source:
ListViewItem.cs
Source:
ListViewItem.cs

Initializes a new instance of the ListViewItem class with the specified subitems, image, and group.

C#
public ListViewItem(System.Windows.Forms.ListViewItem.ListViewSubItem[] subItems, string imageKey, System.Windows.Forms.ListViewGroup group);
C#
public ListViewItem(System.Windows.Forms.ListViewItem.ListViewSubItem[] subItems, string? imageKey, System.Windows.Forms.ListViewGroup? group);

Parameters

subItems
ListViewItem.ListViewSubItem[]

An array of ListViewItem.ListViewSubItem objects that represent the subitems of the ListViewItem.

imageKey
String

The name of the image within the ImageList of the owning ListView to display in the item.

group
ListViewGroup

The ListViewGroup to assign the item to.

Remarks

This version of the constructor is useful when you create ListViewItem.ListViewSubItem objects before adding them to a ListViewItem (for example, to indicate special formatting or to use the subitems in multiple items). It also allows you to specify the group to which an item belongs.

The imageKey parameter specifies an image in the ImageList associated with the owning ListView control, which can be accessed with the ImageList property.

Note

ListView groups are only available on Windows XP and the Windows Server 2003 family (Windows XP Home Edition, Windows XP Professional, Windows Server 2003). For more information, see the ListViewGroup overview topic.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

ListViewItem(ListViewItem+ListViewSubItem[], Int32, ListViewGroup)

Source:
ListViewItem.cs
Source:
ListViewItem.cs
Source:
ListViewItem.cs

Initializes a new instance of the ListViewItem class with the image index position of the item's icon and an array of ListViewItem.ListViewSubItem objects, and assigns the item to the specified group.

C#
public ListViewItem(System.Windows.Forms.ListViewItem.ListViewSubItem[] subItems, int imageIndex, System.Windows.Forms.ListViewGroup group);
C#
public ListViewItem(System.Windows.Forms.ListViewItem.ListViewSubItem[] subItems, int imageIndex, System.Windows.Forms.ListViewGroup? group);

Parameters

subItems
ListViewItem.ListViewSubItem[]

An array of type ListViewItem.ListViewSubItem that represents the subitems of the item.

imageIndex
Int32

The zero-based index of the image within the ImageList associated with the ListView that contains the item.

group
ListViewGroup

The ListViewGroup to assign the item to.

Remarks

This version of the constructor is useful when you create ListViewItem.ListViewSubItem objects before adding them to a ListViewItem object (for example, to indicate special formatting or to use the subitems in multiple items). It also allows you to specify the group to which an item belongs.

Note

ListView groups are only available on Windows XP and the Windows Server 2003 family (Windows XP Home Edition, Windows XP Professional, Windows Server 2003). For more information, see the ListViewGroup overview topic.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

ListViewItem(String[], String, ListViewGroup)

Source:
ListViewItem.cs
Source:
ListViewItem.cs
Source:
ListViewItem.cs

Initializes a new instance of the ListViewItem class with subitems containing the specified text, image, and group.

C#
public ListViewItem(string[] items, string imageKey, System.Windows.Forms.ListViewGroup group);
C#
public ListViewItem(string[]? items, string? imageKey, System.Windows.Forms.ListViewGroup? group);

Parameters

items
String[]

An array of strings that represents the text for subitems of the ListViewItem.

imageKey
String

The name of the image within the ImageList of the owning ListView to display in the item.

group
ListViewGroup

The ListViewGroup to assign the item to.

Remarks

This version of the constructor allows you to specify the group to which an item belongs.

The imageKey parameter specifies an image in the ImageList associated with the owning ListView control, which can be accessed with the ImageList property.

Note

ListView groups are only available on Windows XP and the Windows Server 2003 family (Windows XP Home Edition, Windows XP Professional, Windows Server 2003). For more information, see the ListViewGroup overview topic.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

ListViewItem(String[], Int32, ListViewGroup)

Source:
ListViewItem.cs
Source:
ListViewItem.cs
Source:
ListViewItem.cs

Initializes a new instance of the ListViewItem class with the image index position of the item's icon and an array of strings representing subitems, and assigns the item to the specified group.

C#
public ListViewItem(string[] items, int imageIndex, System.Windows.Forms.ListViewGroup group);
C#
public ListViewItem(string[]? items, int imageIndex, System.Windows.Forms.ListViewGroup? group);

Parameters

items
String[]

An array of strings that represent the subitems of the new item.

imageIndex
Int32

The zero-based index of the image within the ImageList associated with the ListView that contains the item.

group
ListViewGroup

The ListViewGroup to assign the item to.

Remarks

This version of the constructor allows you to specify the group to which an item belongs.

Note

ListView groups are only available on Windows XP and the Windows Server 2003 family (Windows XP Home Edition, Windows XP Professional, Windows Server 2003). For more information, see the ListViewGroup overview topic.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

ListViewItem(String, String, ListViewGroup)

Source:
ListViewItem.cs
Source:
ListViewItem.cs
Source:
ListViewItem.cs

Initializes a new instance of the ListViewItem class with the specified text, image, and group.

C#
public ListViewItem(string text, string imageKey, System.Windows.Forms.ListViewGroup group);
C#
public ListViewItem(string? text, string? imageKey, System.Windows.Forms.ListViewGroup? group);

Parameters

text
String

The text to display for the item. This should not exceed 259 characters.

imageKey
String

The name of the image within the ImageList of the owning ListView to display in the item.

group
ListViewGroup

The ListViewGroup to assign the item to.

Remarks

This version of the constructor allows you to specify the group to which an item belongs.

The imageKey parameter specifies an image in the ImageList associated with the owning ListView control, which can be accessed with the ImageList property.

Note

ListView groups are only available on Windows XP and the Windows Server 2003 family (Windows XP Home Edition, Windows XP Professional, Windows Server 2003). For more information, see the ListViewGroup overview topic.

The text of the ListViewItem should not exceed 259 characters or unexpected behavior could occur.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

ListViewItem(ListViewItem+ListViewSubItem[], String)

Source:
ListViewItem.cs
Source:
ListViewItem.cs
Source:
ListViewItem.cs

Initializes a new instance of the ListViewItem class with the specified subitems and image.

C#
public ListViewItem(System.Windows.Forms.ListViewItem.ListViewSubItem[] subItems, string imageKey);
C#
public ListViewItem(System.Windows.Forms.ListViewItem.ListViewSubItem[] subItems, string? imageKey);

Parameters

imageKey
String

The name of the image within the ImageList of the owning ListView to display in the ListViewItem.

Remarks

The imageKey parameter specifies an image in the ImageList associated with the owning ListView control, which can be accessed with the ImageList property.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

ListViewItem(String, Int32, ListViewGroup)

Source:
ListViewItem.cs
Source:
ListViewItem.cs
Source:
ListViewItem.cs

Initializes a new instance of the ListViewItem class with the specified item text and the image index position of the item's icon, and assigns the item to the specified group.

C#
public ListViewItem(string text, int imageIndex, System.Windows.Forms.ListViewGroup group);
C#
public ListViewItem(string? text, int imageIndex, System.Windows.Forms.ListViewGroup? group);

Parameters

text
String

The text to display for the item. This should not exceed 259 characters.

imageIndex
Int32

The zero-based index of the image within the ImageList associated with the ListView that contains the item.

group
ListViewGroup

The ListViewGroup to assign the item to.

Remarks

This version of the constructor allows you to specify the group to which an item belongs.

Note

ListView groups are only available on Windows XP and the Windows Server 2003 family (Windows XP Home Edition, Windows XP Professional, Windows Server 2003). For more information, see the ListViewGroup overview topic.

The text of the ListViewItem should not exceed 259 characters or unexpected behavior could occur.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

ListViewItem(String[], ListViewGroup)

Source:
ListViewItem.cs
Source:
ListViewItem.cs
Source:
ListViewItem.cs

Initializes a new instance of the ListViewItem class with an array of strings representing subitems, and assigns the item to the specified group.

C#
public ListViewItem(string[] items, System.Windows.Forms.ListViewGroup group);
C#
public ListViewItem(string[]? items, System.Windows.Forms.ListViewGroup? group);

Parameters

items
String[]

An array of strings that represent the subitems of the new item.

group
ListViewGroup

The ListViewGroup to assign the item to.

Remarks

This version of the constructor allows you to specify the group to which an item belongs.

Note

ListView groups are only available on Windows XP and the Windows Server 2003 family (Windows XP Home Edition, Windows XP Professional, Windows Server 2003). For more information, see the ListViewGroup overview topic.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

ListViewItem(String[], String)

Source:
ListViewItem.cs
Source:
ListViewItem.cs
Source:
ListViewItem.cs

Initializes a new instance of the ListViewItem class with the specified item and subitem text and image.

C#
public ListViewItem(string[] items, string imageKey);
C#
public ListViewItem(string[]? items, string? imageKey);

Parameters

items
String[]

An array containing the text of the subitems of the ListViewItem.

imageKey
String

The name of the image within the ImageList of the owning ListView to display in the ListViewItem.

Remarks

The imageKey parameter specifies an image in the ImageList associated with the owning ListView control, which can be accessed with the ImageList property.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

ListViewItem(String[], Int32)

Source:
ListViewItem.cs
Source:
ListViewItem.cs
Source:
ListViewItem.cs

Initializes a new instance of the ListViewItem class with the image index position of the item's icon and an array of strings representing subitems.

C#
public ListViewItem(string[] items, int imageIndex);
C#
public ListViewItem(string[]? items, int imageIndex);

Parameters

items
String[]

An array of strings that represent the subitems of the new item.

imageIndex
Int32

The zero-based index of the image within the ImageList associated with the ListView that contains the item.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

ListViewItem(String, ListViewGroup)

Source:
ListViewItem.cs
Source:
ListViewItem.cs
Source:
ListViewItem.cs

Initializes a new instance of the ListViewItem class with the specified item text and assigns it to the specified group.

C#
public ListViewItem(string text, System.Windows.Forms.ListViewGroup group);
C#
public ListViewItem(string? text, System.Windows.Forms.ListViewGroup? group);

Parameters

text
String

The text to display for the item. This should not exceed 259 characters.

group
ListViewGroup

The ListViewGroup to assign the item to.

Remarks

This version of the constructor allows you to specify the group to which an item belongs.

Note

ListView groups are only available on Windows XP and the Windows Server 2003 family (Windows XP Home Edition, Windows XP Professional, Windows Server 2003). For more information, see the ListViewGroup overview topic.

The text of the ListViewItem should not exceed 259 characters or unexpected behavior could occur.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

ListViewItem(String, String)

Source:
ListViewItem.cs
Source:
ListViewItem.cs
Source:
ListViewItem.cs

Initializes a new instance of the ListViewItem class with the specified text and image.

C#
public ListViewItem(string text, string imageKey);
C#
public ListViewItem(string? text, string? imageKey);

Parameters

text
String

The text to display for the item. This should not exceed 259 characters.

imageKey
String

The name of the image within the ImageList of the owning ListView to display in the ListViewItem.

Remarks

The imageKey parameter specifies an image in the ImageList associated with the owning ListView control, which can be accessed with the ImageList property.

The text of the ListViewItem should not exceed 259 characters or unexpected behavior could occur.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

ListViewItem(String, Int32)

Source:
ListViewItem.cs
Source:
ListViewItem.cs
Source:
ListViewItem.cs

Initializes a new instance of the ListViewItem class with the specified item text and the image index position of the item's icon.

C#
public ListViewItem(string text, int imageIndex);
C#
public ListViewItem(string? text, int imageIndex);

Parameters

text
String

The text to display for the item. This should not exceed 259 characters.

imageIndex
Int32

The zero-based index of the image within the ImageList associated with the ListView that contains the item.

Remarks

The text of the ListViewItem should not exceed 259 characters or unexpected behavior could occur.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

ListViewItem(SerializationInfo, StreamingContext)

Source:
ListViewItem.cs
Source:
ListViewItem.cs
Source:
ListViewItem.cs

Initializes a new instance of the ListViewItem class with the specified serialization information and streaming context.

C#
protected ListViewItem(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);

Parameters

info
SerializationInfo

A SerializationInfo containing information about the ListViewItem to be initialized.

context
StreamingContext

A StreamingContext that indicates the source destination and context information of a serialized stream.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

ListViewItem(ListViewGroup)

Source:
ListViewItem.cs
Source:
ListViewItem.cs
Source:
ListViewItem.cs

Initializes a new instance of the ListViewItem class and assigns it to the specified group.

C#
public ListViewItem(System.Windows.Forms.ListViewGroup group);
C#
public ListViewItem(System.Windows.Forms.ListViewGroup? group);

Parameters

group
ListViewGroup

The ListViewGroup to assign the item to.

Remarks

This version of the constructor allows you to specify the group to which an item belongs.

Note

ListView groups are only available on Windows XP and the Windows Server 2003 family (Windows XP Home Edition, Windows XP Professional, Windows Server 2003). For more information, see the ListViewGroup overview topic.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

ListViewItem(String[])

Source:
ListViewItem.cs
Source:
ListViewItem.cs
Source:
ListViewItem.cs

Initializes a new instance of the ListViewItem class with an array of strings representing subitems.

C#
public ListViewItem(string[] items);
C#
public ListViewItem(string[]? items);

Parameters

items
String[]

An array of strings that represent the subitems of the new item.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

ListViewItem(String)

Source:
ListViewItem.cs
Source:
ListViewItem.cs
Source:
ListViewItem.cs

Initializes a new instance of the ListViewItem class with the specified item text.

C#
public ListViewItem(string text);
C#
public ListViewItem(string? text);

Parameters

text
String

The text to display for the item. This should not exceed 259 characters.

Remarks

The text of the ListViewItem should not exceed 259 characters or unexpected behavior could occur.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

ListViewItem(ListViewItem+ListViewSubItem[], Int32)

Source:
ListViewItem.cs
Source:
ListViewItem.cs
Source:
ListViewItem.cs

Initializes a new instance of the ListViewItem class with the image index position of the item's icon and an array of ListViewItem.ListViewSubItem objects.

C#
public ListViewItem(System.Windows.Forms.ListViewItem.ListViewSubItem[] subItems, int imageIndex);

Parameters

subItems
ListViewItem.ListViewSubItem[]

An array of type ListViewItem.ListViewSubItem that represents the subitems of the item.

imageIndex
Int32

The zero-based index of the image within the ImageList associated with the ListView that contains the item.

Remarks

This version of the constructor is useful when you create ListViewItem.ListViewSubItem objects before adding them to a ListViewItem (for example, to indicate special formatting or to use the subitems in multiple items).

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10