ListViewItem 构造函数

定义

初始化 ListViewItem 类的新实例。

重载

ListViewItem()

使用默认值初始化 ListViewItem 类的新实例。

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

用包含指定的文本、图像、颜色、字体和组的子项初始化 ListViewItem 类的新实例。

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

用项图标的图像索引位置、前景色、背景色、项的字体和表示子项的字符串数组初始化 ListViewItem 类的新实例。 将该项分配到指定的组。

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

用包含指定的文本、图像、颜色和字体的子项初始化 ListViewItem 类的新实例。

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

用项图标的图像索引位置、前景色、背景色、项的字体和表示子项的字符串数组初始化 ListViewItem 类的新实例。

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

用指定的子项、图像和组初始化 ListViewItem 类的新实例。

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

用项图标的图像索引位置和 ListViewItem 对象的数组初始化 ListViewItem.ListViewSubItem 类的新实例,并将该项分配到指定的组。

ListViewItem(String[], String, ListViewGroup)

用包含指定文本、图像和组的子项初始化 ListViewItem 类的新实例。

ListViewItem(String[], Int32, ListViewGroup)

用项图标的图像索引位置和表示子项的字符串数组初始化 ListViewItem 类的新实例,并将该项分配到指定的组。

ListViewItem(String, String, ListViewGroup)

用指定的文本、图像和组初始化 ListViewItem 类的新实例。

ListViewItem(ListViewItem+ListViewSubItem[], String)

用指定的子项和图像初始化 ListViewItem 类的新实例。

ListViewItem(String, Int32, ListViewGroup)

用指定的项文本和项图标的图像索引位置初始化 ListViewItem 类的新实例,并将该项分配到指定的组。

ListViewItem(String[], ListViewGroup)

用表示子项的字符串数组初始化 ListViewItem 类的新实例,并将该项分配到指定的组。

ListViewItem(String[], String)

用指定的项和子项文本及图像初始化 ListViewItem 类的新实例。

ListViewItem(String[], Int32)

用项图标的图像索引位置和表示子项的字符串数组初始化 ListViewItem 类的新实例。

ListViewItem(String, ListViewGroup)

用指定的项文本初始化 ListViewItem 类的新实例,并将它分配到指定的组。

ListViewItem(String, String)

用指定的文本和图像初始化 ListViewItem 类的新实例。

ListViewItem(String, Int32)

用指定的项文本和项图标的图像索引位置初始化 ListViewItem 类的新实例。

ListViewItem(SerializationInfo, StreamingContext)

使用指定的序列化信息和流上下文初始化 ListViewItem 类的新实例。

ListViewItem(ListViewGroup)

初始化 ListViewItem 类的新实例,并将它分配到指定的组。

ListViewItem(String[])

用表示子项的字符串数组初始化 ListViewItem 类的新实例。

ListViewItem(String)

用指定的项文本初始化 ListViewItem 类的新实例。

ListViewItem(ListViewItem+ListViewSubItem[], Int32)

用项图标的图像索引位置和 ListViewItem 对象的数组初始化 ListViewItem.ListViewSubItem 类的新实例。

ListViewItem()

使用默认值初始化 ListViewItem 类的新实例。

C#
public ListViewItem ();

示例

下面的代码示例创建一个控件,其中为每个项指定了三ListViewItemListView 对象和三个 ListViewItem.ListViewSubItem 对象。 该示例还创建 ColumnHeader 对象以在详细信息视图中显示子项。 此外,在代码示例中创建两 ImageList 个对象来为 ListViewItem 对象提供图像。 这些 ImageList 对象将添加到 LargeImageListSmallImageList 属性中。 该示例在创建 ListView 控件时使用以下属性:

需要将代码添加到 , Form 并从窗体上的构造函数或另一个方法调用示例中创建的方法。 该示例要求名为 MySmallImage1MySmallImage2MyLargeImage1MyLargeImage2 的映像位于驱动器 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);
}

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.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

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

用包含指定的文本、图像、颜色、字体和组的子项初始化 ListViewItem 类的新实例。

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);

参数

items
String[]

一个字符串数组,表示 ListViewItem 的子项的文本。

imageKey
String

所属 ImageListListView 中的图像的名称,将在该项中显示该名称。

foreColor
Color

Color,表示该项的前景色。

backColor
Color

Color,表示该项的背景色。

font
Font

要应用于项文本的 Font

group
ListViewGroup

要将项分配到的 ListViewGroup

注解

此版本的构造函数允许您指定项所属的组。

参数imageKey指定与拥有ListView控件关联的 中的ImageList图像,该图像可通过 属性进行访问ImageList

备注

ListView 组仅适用于 Windows XP 和 Windows Server 2003 系列 (Windows XP Home Edition、Windows XP Professional、Windows Server 2003) 。 有关更多信息,请参见 ListViewGroup 概述主题。

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.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

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

用项图标的图像索引位置、前景色、背景色、项的字体和表示子项的字符串数组初始化 ListViewItem 类的新实例。 将该项分配到指定的组。

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);

参数

items
String[]

表示此新项的子项的字符串数组。

imageIndex
Int32

图像的从零开始的索引,该图像位于与包含该项的 ImageList 关联的 ListView 中。

foreColor
Color

Color,表示该项的前景色。

backColor
Color

Color,表示该项的背景色。

font
Font

Font,表示用于显示该项文本的字体。

group
ListViewGroup

要将项分配到的 ListViewGroup

注解

此版本的构造函数允许您指定项所属的组。

备注

ListView 组仅适用于 Windows XP 和 Windows Server 2003 系列 (Windows XP Home Edition、Windows XP Professional、Windows Server 2003) 。 有关更多信息,请参见 ListViewGroup 概述主题。

另请参阅

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.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

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

用包含指定的文本、图像、颜色和字体的子项初始化 ListViewItem 类的新实例。

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);

参数

items
String[]

一个字符串数组,表示 ListViewItem 的子项的文本。

imageKey
String

所属 ImageListListView 中的图像的名称,将在该项中显示该名称。

foreColor
Color

Color,表示该项的前景色。

backColor
Color

Color,表示该项的背景色。

font
Font

要应用于项文本的 Font

注解

参数imageKey指定与拥有ListView控件关联的 中的ImageList图像,该图像可通过 属性进行访问ImageList

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.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

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

用项图标的图像索引位置、前景色、背景色、项的字体和表示子项的字符串数组初始化 ListViewItem 类的新实例。

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);

参数

items
String[]

表示此新项的子项的字符串数组。

imageIndex
Int32

图像的从零开始的索引,该图像位于与包含该项的 ImageList 关联的 ListView 中。

foreColor
Color

Color,表示该项的前景色。

backColor
Color

Color,表示该项的背景色。

font
Font

Font,表示用于显示该项文本的字体。

示例

下面的代码示例创建一个窗体,该窗体包含一个 ListView 控件,该控件在单击控件中的 ListView 列时手动对项进行排序。 该示例定义一个名为 的 ListViewItemComparer 类,该类实现 System.Collections.IComparer 执行比较的 ListViewItem 接口。 该示例创建 的 ListViewItemComparer 实例,并使用它来设置 ListViewItemSorter 控件的 ListView 属性。 Sort事件处理程序中的 ColumnClick 方法调用使用 中ListViewItemComparer定义的方法根据单击的列执行项排序。

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);
        }
    }
}

另请参阅

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.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

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

用指定的子项、图像和组初始化 ListViewItem 类的新实例。

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);

参数

subItems
ListViewItem.ListViewSubItem[]

ListViewItem.ListViewSubItem 对象的数组,表示 ListViewItem 的子项。

imageKey
String

所属 ImageListListView 中的图像的名称,将在该项中显示该名称。

group
ListViewGroup

要将项分配到的 ListViewGroup

注解

在将对象添加到ListViewItem (之前创建ListViewItem.ListViewSubItem对象时,此版本的构造函数非常有用,例如,用于指示特殊格式或在多个项中使用子项) 。 它还允许指定项所属的组。

参数imageKey指定与拥有ListView控件关联的 中的ImageList图像,可以使用 属性访问ImageList该图像。

备注

ListView 组仅适用于 Windows XP 和 Windows Server 2003 系列 (Windows XP Home Edition、Windows XP Professional、Windows Server 2003) 。 有关更多信息,请参见 ListViewGroup 概述主题。

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.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

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

用项图标的图像索引位置和 ListViewItem 对象的数组初始化 ListViewItem.ListViewSubItem 类的新实例,并将该项分配到指定的组。

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);

参数

subItems
ListViewItem.ListViewSubItem[]

ListViewItem.ListViewSubItem 类型的数组,表示该项的子项。

imageIndex
Int32

图像的从零开始的索引,该图像位于与包含该项的 ImageList 关联的 ListView 中。

group
ListViewGroup

要将项分配到的 ListViewGroup

注解

此版本的构造函数在将对象添加到ListViewItem对象之前创建ListViewItem.ListViewSubItem对象时非常有用 (例如,指示特殊格式或在多个项中使用子项) 。 它还允许指定项所属的组。

备注

ListView 组仅适用于 Windows XP 和 Windows Server 2003 系列 (Windows XP Home Edition、Windows XP Professional、Windows Server 2003) 。 有关更多信息,请参见 ListViewGroup 概述主题。

另请参阅

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.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

ListViewItem(String[], String, ListViewGroup)

用包含指定文本、图像和组的子项初始化 ListViewItem 类的新实例。

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

参数

items
String[]

一个字符串数组,表示 ListViewItem 的子项的文本。

imageKey
String

所属 ImageListListView 中的图像的名称,将在该项中显示该名称。

group
ListViewGroup

要将项分配到的 ListViewGroup

注解

此版本的构造函数允许指定项所属的组。

参数imageKey指定与拥有ListView控件关联的 中的ImageList图像,可以使用 属性访问ImageList该图像。

备注

ListView 组仅适用于 Windows XP 和 Windows Server 2003 系列 (Windows XP Home Edition、Windows XP Professional、Windows Server 2003) 。 有关更多信息,请参见 ListViewGroup 概述主题。

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.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

ListViewItem(String[], Int32, ListViewGroup)

用项图标的图像索引位置和表示子项的字符串数组初始化 ListViewItem 类的新实例,并将该项分配到指定的组。

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

参数

items
String[]

表示此新项的子项的字符串数组。

imageIndex
Int32

图像的从零开始的索引,该图像位于与包含该项的 ImageList 关联的 ListView 中。

group
ListViewGroup

要将项分配到的 ListViewGroup

注解

此版本的构造函数允许指定项所属的组。

备注

ListView 组仅适用于 Windows XP 和 Windows Server 2003 系列 (Windows XP Home Edition、Windows XP Professional、Windows Server 2003) 。 有关更多信息,请参见 ListViewGroup 概述主题。

另请参阅

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.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

ListViewItem(String, String, ListViewGroup)

用指定的文本、图像和组初始化 ListViewItem 类的新实例。

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

参数

text
String

要为该项显示的文本。 该文本不应该超过 259 个字符。

imageKey
String

所属 ImageListListView 中的图像的名称,将在该项中显示该名称。

group
ListViewGroup

要将项分配到的 ListViewGroup

注解

此版本的构造函数允许指定项所属的组。

参数imageKey指定与拥有ListView控件关联的 中的ImageList图像,可以使用 属性访问ImageList该图像。

备注

ListView 组仅适用于 Windows XP 和 Windows Server 2003 系列 (Windows XP Home Edition、Windows XP Professional、Windows Server 2003) 。 有关更多信息,请参见 ListViewGroup 概述主题。

的文本 ListViewItem 不应超过 259 个字符,否则可能会出现意外行为。

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.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

ListViewItem(ListViewItem+ListViewSubItem[], String)

用指定的子项和图像初始化 ListViewItem 类的新实例。

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

参数

imageKey
String

所属 ImageListListView 中的图像的名称,将在 ListViewItem 中显示该名称。

注解

参数imageKey指定与拥有ListView控件关联的 中的ImageList图像,可以使用 属性访问ImageList该图像。

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.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

ListViewItem(String, Int32, ListViewGroup)

用指定的项文本和项图标的图像索引位置初始化 ListViewItem 类的新实例,并将该项分配到指定的组。

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

参数

text
String

要为该项显示的文本。 该文本不应该超过 259 个字符。

imageIndex
Int32

图像的从零开始的索引,该图像位于与包含该项的 ImageList 关联的 ListView 中。

group
ListViewGroup

要将项分配到的 ListViewGroup

注解

此版本的构造函数允许指定项所属的组。

备注

ListView 组仅适用于 Windows XP 和 Windows Server 2003 系列 (Windows XP Home Edition、Windows XP Professional、Windows Server 2003) 。 有关更多信息,请参见 ListViewGroup 概述主题。

的文本 ListViewItem 不应超过 259 个字符,否则可能会出现意外行为。

另请参阅

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.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

ListViewItem(String[], ListViewGroup)

用表示子项的字符串数组初始化 ListViewItem 类的新实例,并将该项分配到指定的组。

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

参数

items
String[]

表示此新项的子项的字符串数组。

group
ListViewGroup

要将项分配到的 ListViewGroup

注解

此版本的构造函数允许指定项所属的组。

备注

ListView 组仅适用于 Windows XP 和 Windows Server 2003 系列 (Windows XP Home Edition、Windows XP Professional、Windows Server 2003) 。 有关更多信息,请参见 ListViewGroup 概述主题。

另请参阅

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.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

ListViewItem(String[], String)

用指定的项和子项文本及图像初始化 ListViewItem 类的新实例。

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

参数

items
String[]

一个数组,它包含 ListViewItem 的子项的文本。

imageKey
String

所属 ImageListListView 中的图像的名称,将在 ListViewItem 中显示该名称。

注解

参数imageKey指定与拥有ListView控件关联的 中的ImageList图像,可以使用 属性访问ImageList该图像。

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.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

ListViewItem(String[], Int32)

用项图标的图像索引位置和表示子项的字符串数组初始化 ListViewItem 类的新实例。

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

参数

items
String[]

表示此新项的子项的字符串数组。

imageIndex
Int32

图像的从零开始的索引,该图像位于与包含该项的 ImageList 关联的 ListView 中。

另请参阅

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.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

ListViewItem(String, ListViewGroup)

用指定的项文本初始化 ListViewItem 类的新实例,并将它分配到指定的组。

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

参数

text
String

要为该项显示的文本。 该文本不应该超过 259 个字符。

group
ListViewGroup

要将项分配到的 ListViewGroup

注解

此版本的构造函数允许指定项所属的组。

备注

ListView 组仅适用于 Windows XP 和 Windows Server 2003 系列 (Windows XP Home Edition、Windows XP Professional、Windows Server 2003) 。 有关更多信息,请参见 ListViewGroup 概述主题。

的文本 ListViewItem 不应超过 259 个字符,否则可能会出现意外行为。

另请参阅

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.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

ListViewItem(String, String)

用指定的文本和图像初始化 ListViewItem 类的新实例。

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

参数

text
String

要为该项显示的文本。 该文本不应该超过 259 个字符。

imageKey
String

所属 ImageListListView 中的图像的名称,将在 ListViewItem 中显示该名称。

注解

参数imageKey指定与拥有ListView控件关联的 中的ImageList图像,可以使用 属性访问ImageList该图像。

的文本 ListViewItem 不应超过 259 个字符,否则可能会出现意外行为。

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.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

ListViewItem(String, Int32)

用指定的项文本和项图标的图像索引位置初始化 ListViewItem 类的新实例。

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

参数

text
String

要为该项显示的文本。 该文本不应该超过 259 个字符。

imageIndex
Int32

图像的从零开始的索引,该图像位于与包含该项的 ImageList 关联的 ListView 中。

注解

的文本 ListViewItem 不应超过 259 个字符,否则可能会出现意外行为。

另请参阅

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.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

ListViewItem(SerializationInfo, StreamingContext)

使用指定的序列化信息和流上下文初始化 ListViewItem 类的新实例。

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

参数

info
SerializationInfo

一个 SerializationInfo,包含关于要初始化的 ListViewItem 的信息。

context
StreamingContext

一个 StreamingContext,指示序列化的流的源和目标以及上下文信息。

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.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

ListViewItem(ListViewGroup)

初始化 ListViewItem 类的新实例,并将它分配到指定的组。

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

参数

group
ListViewGroup

要将项分配到的 ListViewGroup

注解

此版本的构造函数允许指定项所属的组。

备注

ListView 组仅适用于 Windows XP 和 Windows Server 2003 系列 (Windows XP Home Edition、Windows XP Professional、Windows Server 2003) 。 有关更多信息,请参见 ListViewGroup 概述主题。

另请参阅

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.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

ListViewItem(String[])

用表示子项的字符串数组初始化 ListViewItem 类的新实例。

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

参数

items
String[]

表示此新项的子项的字符串数组。

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.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

ListViewItem(String)

用指定的项文本初始化 ListViewItem 类的新实例。

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

参数

text
String

要为该项显示的文本。 该文本不应该超过 259 个字符。

注解

的文本 ListViewItem 不应超过 259 个字符,否则可能会出现意外行为。

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.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

ListViewItem(ListViewItem+ListViewSubItem[], Int32)

用项图标的图像索引位置和 ListViewItem 对象的数组初始化 ListViewItem.ListViewSubItem 类的新实例。

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

参数

subItems
ListViewItem.ListViewSubItem[]

ListViewItem.ListViewSubItem 类型的数组,表示该项的子项。

imageIndex
Int32

图像的从零开始的索引,该图像位于与包含该项的 ImageList 关联的 ListView 中。

注解

在将对象添加到ListViewItem (之前创建ListViewItem.ListViewSubItem对象时,此版本的构造函数非常有用,例如,用于指示特殊格式或在多个项中使用子项) 。

另请参阅

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.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