ListViewItem Constructors

Definition

初始化 ListViewItem 类的新实例。Initializes a new instance of the ListViewItem class.

Overloads

ListViewItem()

使用默认值初始化 ListViewItem 类的新实例。Initializes a new instance of the ListViewItem class with default values.

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

用包含指定的文本、图像、颜色、字体和组的子项初始化 ListViewItem 类的新实例。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)

用项图标的图像索引位置、前景色、背景色、项的字体和表示子项的字符串数组初始化 ListViewItem 类的新实例。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)

用包含指定的文本、图像、颜色和字体的子项初始化 ListViewItem 类的新实例。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)

用项图标的图像索引位置、前景色、背景色、项的字体和表示子项的字符串数组初始化 ListViewItem 类的新实例。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)

用指定的子项、图像和组初始化 ListViewItem 类的新实例。Initializes a new instance of the ListViewItem class with the specified subitems, image, and group.

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

用项图标的图像索引位置和 ListViewItem 对象的数组初始化 ListViewItem.ListViewSubItem 类的新实例,并将该项分配到指定的组。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)

用包含指定文本、图像和组的子项初始化 ListViewItem 类的新实例。Initializes a new instance of the ListViewItem class with subitems containing the specified text, image, and group.

ListViewItem(String[], Int32, ListViewGroup)

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

用指定的文本、图像和组初始化 ListViewItem 类的新实例。Initializes a new instance of the ListViewItem class with the specified text, image, and group.

ListViewItem(ListViewItem+ListViewSubItem[], String)

用指定的子项和图像初始化 ListViewItem 类的新实例。Initializes a new instance of the ListViewItem class with the specified subitems and image.

ListViewItem(String, Int32, ListViewGroup)

用指定的项文本和项图标的图像索引位置初始化 ListViewItem 类的新实例,并将该项分配到指定的组。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)

用表示子项的字符串数组初始化 ListViewItem 类的新实例,并将该项分配到指定的组。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)

用指定的项和子项文本及图像初始化 ListViewItem 类的新实例。Initializes a new instance of the ListViewItem class with the specified item and subitem text and image.

ListViewItem(String[], Int32)

用项图标的图像索引位置和表示子项的字符串数组初始化 ListViewItem 类的新实例。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)

用指定的项文本初始化 ListViewItem 类的新实例,并将它分配到指定的组。Initializes a new instance of the ListViewItem class with the specified item text and assigns it to the specified group.

ListViewItem(String, String)

用指定的文本和图像初始化 ListViewItem 类的新实例。Initializes a new instance of the ListViewItem class with the specified text and image.

ListViewItem(String, Int32)

用指定的项文本和项图标的图像索引位置初始化 ListViewItem 类的新实例。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)

使用指定的序列化信息和流上下文初始化 ListViewItem 类的新实例。Initializes a new instance of the ListViewItem class with the specified serialization information and streaming context.

ListViewItem(ListViewGroup)

初始化 ListViewItem 类的新实例,并将它分配到指定的组。Initializes a new instance of the ListViewItem class and assigns it to the specified group.

ListViewItem(String[])

用表示子项的字符串数组初始化 ListViewItem 类的新实例。Initializes a new instance of the ListViewItem class with an array of strings representing subitems.

ListViewItem(String)

用指定的项文本初始化 ListViewItem 类的新实例。Initializes a new instance of the ListViewItem class with the specified item text.

ListViewItem(ListViewItem+ListViewSubItem[], Int32)

用项图标的图像索引位置和 ListViewItem 对象的数组初始化 ListViewItem.ListViewSubItem 类的新实例。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()

使用默认值初始化 ListViewItem 类的新实例。Initializes a new instance of the ListViewItem class with default values.

public:
 ListViewItem();
public ListViewItem ();
Public Sub New ()

Examples

下面的代码示例创建一个 ListView 控件,其中指定了三个 ListViewItem 对象和为每个项指定了三个 ListViewItem.ListViewSubItem 对象。The following code example creates a ListView control with three ListViewItem objects specified and three ListViewItem.ListViewSubItem objects specified for each item. 该示例还创建 ColumnHeader 对象以在详细信息视图中显示子项。The example also creates ColumnHeader objects to display the subitems in details view. 在代码示例中还会创建两个 ImageList 对象,以便为 ListViewItem 对象提供图像。Two ImageList objects are also created in the code example to provide images for the ListViewItem objects. 这些 ImageList 对象将添加到 LargeImageListSmallImageList 属性。These ImageList objects are added to the LargeImageList and SmallImageList properties. 该示例使用以下属性创建 ListView 控件:The example uses the following properties in creating the ListView control:

需要将代码添加到 Form,并从构造函数或窗体上的其他方法调用在示例中创建的方法。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. 该示例要求名为 MySmallImage1MySmallImage2MyLargeImage1MyLargeImage2 的映像位于驱动器 C 的根目录中。The example requires that images named MySmallImage1, MySmallImage2, MyLargeImage1, and MyLargeImage2 are located in the root directory of drive C.

private:
   void CreateMyListView()
   {
      // Create a new ListView control.
      ListView^ listView1 = gcnew ListView;
      listView1->Bounds = Rectangle(Point(10,10),System::Drawing::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 = gcnew 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 = gcnew ListViewItem( "item2",1 );
      item2->SubItems->Add( "4" );
      item2->SubItems->Add( "5" );
      item2->SubItems->Add( "6" );
      ListViewItem^ item3 = gcnew 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.
      array<ListViewItem^>^temp1 = {item1,item2,item3};
      listView1->Items->AddRange( temp1 );

      // Create two ImageList objects.
      ImageList^ imageListSmall = gcnew ImageList;
      ImageList^ imageListLarge = gcnew 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 );
   }
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);
}
Private Sub CreateMyListView()
    ' Create a new ListView control.
    Dim listView1 As 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.
    Dim item1 As 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")
    Dim item2 As New ListViewItem("item2", 1)
    item2.SubItems.Add("4")
    item2.SubItems.Add("5")
    item2.SubItems.Add("6")
    Dim item3 As 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.
    Dim imageListSmall As New ImageList()
    Dim imageListLarge As 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.
    Me.Controls.Add(listView1)
End Sub

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

用包含指定的文本、图像、颜色、字体和组的子项初始化 ListViewItem 类的新实例。Initializes a new instance of the ListViewItem class with the subitems containing the specified text, image, colors, font, and group.

public:
 ListViewItem(cli::array <System::String ^> ^ items, System::String ^ imageKey, System::Drawing::Color foreColor, System::Drawing::Color backColor, System::Drawing::Font ^ font, System::Windows::Forms::ListViewGroup ^ group);
public ListViewItem (string[] items, string imageKey, System.Drawing.Color foreColor, System.Drawing.Color backColor, System.Drawing.Font font, System.Windows.Forms.ListViewGroup group);
new System.Windows.Forms.ListViewItem : string[] * string * System.Drawing.Color * System.Drawing.Color * System.Drawing.Font * System.Windows.Forms.ListViewGroup -> System.Windows.Forms.ListViewItem
Public Sub New (items As String(), imageKey As String, foreColor As Color, backColor As Color, font As Font, group As ListViewGroup)

Parameters

items
String[]

一个字符串数组,表示 ListViewItem 的子项的文本。An array of strings that represents the text of the subitems for the ListViewItem.

imageKey
String

所属 ImageListListView 中的图像的名称,将在该项中显示该名称。The name of the image within the ImageList of the owning ListView to display in the item.

foreColor
Color

Color,表示该项的前景色。A Color that represents the foreground color of the item.

backColor
Color

Color,表示该项的背景色。A Color that represents the background color of the item.

font
Font

要应用于项文本的 FontA Font to apply to the item text.

group
ListViewGroup

要将项分配到的 ListViewGroupThe ListViewGroup to assign the item to.

Remarks

此版本的构造函数允许您指定项所属的组。This version of the constructor allows you to specify the group to which an item belongs.

imageKey 参数在与拥有的 ListView 控件关联的 ImageList 中指定一个图像,该图像可使用 ImageList 属性进行访问。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 组仅适用于 Windows XP 和 Windows Server 2003 家族(Windows XP Home Edition、Windows XP Professional、Windows Server 2003Windows XP Home Edition, Windows XP Professional, Windows Server 2003)。ListView groups are only available on Windows XP and the Windows Server 2003 family (Windows XP Home Edition、Windows XP Professional、Windows Server 2003Windows XP Home Edition, Windows XP Professional, Windows Server 2003). 有关更多信息,请参见 ListViewGroup 概述主题。For more information, see the ListViewGroup overview topic.

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

用项图标的图像索引位置、前景色、背景色、项的字体和表示子项的字符串数组初始化 ListViewItem 类的新实例。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.

public:
 ListViewItem(cli::array <System::String ^> ^ items, int imageIndex, System::Drawing::Color foreColor, System::Drawing::Color backColor, System::Drawing::Font ^ font, System::Windows::Forms::ListViewGroup ^ group);
public ListViewItem (string[] items, int imageIndex, System.Drawing.Color foreColor, System.Drawing.Color backColor, System.Drawing.Font font, System.Windows.Forms.ListViewGroup group);
new System.Windows.Forms.ListViewItem : string[] * int * System.Drawing.Color * System.Drawing.Color * System.Drawing.Font * System.Windows.Forms.ListViewGroup -> System.Windows.Forms.ListViewItem
Public Sub New (items As String(), imageIndex As Integer, foreColor As Color, backColor As Color, font As Font, group As ListViewGroup)

Parameters

items
String[]

表示此新项的子项的字符串数组。An array of strings that represent the subitems of the new item.

imageIndex
Int32

图像的从零开始的索引,该图像位于与包含该项的 ImageList 关联的 ListView 中。The zero-based index of the image within the ImageList associated with the ListView that contains the item.

foreColor
Color

Color,表示该项的前景色。A Color that represents the foreground color of the item.

backColor
Color

Color,表示该项的背景色。A Color that represents the background color of the item.

font
Font

Font,表示用于显示该项文本的字体。A Font that represents the font to display the item's text in.

group
ListViewGroup

要将项分配到的 ListViewGroupThe 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 组仅适用于 Windows XP 和 Windows Server 2003 家族(Windows XP Home Edition、Windows XP Professional、Windows Server 2003Windows XP Home Edition, Windows XP Professional, Windows Server 2003)。ListView groups are only available on Windows XP and the Windows Server 2003 family (Windows XP Home Edition、Windows XP Professional、Windows Server 2003Windows XP Home Edition, Windows XP Professional, Windows Server 2003). 有关更多信息,请参见 ListViewGroup 概述主题。For more information, see the ListViewGroup overview topic.

See also

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

用包含指定的文本、图像、颜色和字体的子项初始化 ListViewItem 类的新实例。Initializes a new instance of the ListViewItem class with the subitems containing the specified text, image, colors, and font.

public:
 ListViewItem(cli::array <System::String ^> ^ items, System::String ^ imageKey, System::Drawing::Color foreColor, System::Drawing::Color backColor, System::Drawing::Font ^ font);
public ListViewItem (string[] items, string imageKey, System.Drawing.Color foreColor, System.Drawing.Color backColor, System.Drawing.Font font);
new System.Windows.Forms.ListViewItem : string[] * string * System.Drawing.Color * System.Drawing.Color * System.Drawing.Font -> System.Windows.Forms.ListViewItem
Public Sub New (items As String(), imageKey As String, foreColor As Color, backColor As Color, font As Font)

Parameters

items
String[]

一个字符串数组,表示 ListViewItem 的子项的文本。An array of strings that represent the text of the subitems for the ListViewItem.

imageKey
String

所属 ImageListListView 中的图像的名称,将在该项中显示该名称。The name of the image within the ImageList of the owning ListView to display in the item.

foreColor
Color

Color,表示该项的前景色。A Color that represents the foreground color of the item.

backColor
Color

Color,表示该项的背景色。A Color that represents the background color of the item.

font
Font

要应用于项文本的 FontA Font to apply to the item text.

Remarks

imageKey 参数在与拥有的 ListView 控件关联的 ImageList 中指定一个图像,该图像可使用 ImageList 属性进行访问。The imageKey parameter specifies an image in the ImageList associated with the owning ListView control, which can be accessed with the ImageList property.

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

用项图标的图像索引位置、前景色、背景色、项的字体和表示子项的字符串数组初始化 ListViewItem 类的新实例。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.

public:
 ListViewItem(cli::array <System::String ^> ^ items, int imageIndex, System::Drawing::Color foreColor, System::Drawing::Color backColor, System::Drawing::Font ^ font);
public ListViewItem (string[] items, int imageIndex, System.Drawing.Color foreColor, System.Drawing.Color backColor, System.Drawing.Font font);
new System.Windows.Forms.ListViewItem : string[] * int * System.Drawing.Color * System.Drawing.Color * System.Drawing.Font -> System.Windows.Forms.ListViewItem
Public Sub New (items As String(), imageIndex As Integer, foreColor As Color, backColor As Color, font As Font)

Parameters

items
String[]

表示此新项的子项的字符串数组。An array of strings that represent the subitems of the new item.

imageIndex
Int32

图像的从零开始的索引,该图像位于与包含该项的 ImageList 关联的 ListView 中。The zero-based index of the image within the ImageList associated with the ListView that contains the item.

foreColor
Color

Color,表示该项的前景色。A Color that represents the foreground color of the item.

backColor
Color

Color,表示该项的背景色。A Color that represents the background color of the item.

font
Font

Font,表示用于显示该项文本的字体。A Font that represents the font to display the item's text in.

Examples

下面的代码示例创建一个窗体,该窗体包含一个 ListView 控件,该控件在单击 ListView 控件中的列时手动对项进行排序。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. 该示例定义了一个名为 ListViewItemComparer 的类,该类实现执行 ListViewItem 比较的 System.Collections.IComparer 接口。The example defines a class called ListViewItemComparer that implements the System.Collections.IComparer interface that performs the ListViewItem comparison. 该示例创建一个 ListViewItemComparer 实例,并使用它来设置 ListView 控件的 ListViewItemSorter 属性。The example creates an instance of ListViewItemComparer and uses it to set the ListViewItemSorter property of the ListView control. ColumnClick 事件处理程序中的 Sort 方法调用使用在 ListViewItemComparer 中定义的方法,根据所单击的列来执行项的排序。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.

#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>

using namespace System;
using namespace System::Windows::Forms;
using namespace System::Drawing;
using namespace System::Collections;

// Implements the manual sorting of items by columns.
ref class ListViewItemComparer: public IComparer
{
private:
   int col;

public:
   ListViewItemComparer()
   {
      col = 0;
   }

   ListViewItemComparer( int column )
   {
      col = column;
   }

   virtual int Compare( Object^ x, Object^ y )
   {
      return String::Compare( (dynamic_cast<ListViewItem^>(x))->SubItems[ col ]->Text,
                              (dynamic_cast<ListViewItem^>(y))->SubItems[ col ]->Text );
   }
};

public ref class ListViewSortForm: public Form
{
private:
   ListView^ listView1;

public:
   ListViewSortForm()
   {
      // Create ListView items to add to the control.
      array<String^>^temp0 = {"Banana","a","b","c"};
      ListViewItem^ listViewItem1 = gcnew ListViewItem( temp0,-1,Color::Empty,Color::Yellow,nullptr );
      array<String^>^temp1 = {"Cherry","v","g","t"};
      ListViewItem^ listViewItem2 = gcnew ListViewItem( temp1,-1,Color::Empty,Color::Red,
                 gcnew System::Drawing::Font( "Microsoft Sans Serif",8.25F,FontStyle::Regular,GraphicsUnit::Point,0 ) );
      array<String^>^temp2 = {"Apple","h","j","n"};
      ListViewItem^ listViewItem3 = gcnew ListViewItem( temp2,-1,Color::Empty,Color::Lime,nullptr );
      array<String^>^temp3 = {"Pear","y","u","i"};
      ListViewItem^ listViewItem4 = gcnew ListViewItem( temp3,-1,Color::Empty,Color::FromArgb( 192, 128, 156 ),nullptr );

      //Initialize the ListView control and add columns to it.
      this->listView1 = gcnew 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( gcnew ColumnHeader );
      this->listView1->Columns[ 0 ]->Text = "Column 1";
      this->listView1->Columns[ 0 ]->Width = 100;
      listView1->Columns->Add( gcnew ColumnHeader );
      listView1->Columns[ 1 ]->Text = "Column 2";
      listView1->Columns->Add( gcnew ColumnHeader );
      listView1->Columns[ 2 ]->Text = "Column 3";
      listView1->Columns->Add( gcnew ColumnHeader );
      listView1->Columns[ 3 ]->Text = "Column 4";

      // Suspend control logic until form is done configuring form.
      this->SuspendLayout();

      // Add Items to the ListView control.
      array<ListViewItem^>^temp4 = {listViewItem1,listViewItem2,listViewItem3,listViewItem4};
      this->listView1->Items->AddRange( temp4 );

      // Set the location and size of the ListView control.
      this->listView1->Location = Point(10,10);
      this->listView1->Name = "listView1";
      this->listView1->Size = System::Drawing::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 += gcnew ColumnClickEventHandler( this, &ListViewSortForm::ColumnClick );

      // Initialize the form.
      this->ClientSize = System::Drawing::Size( 400, 400 );
      array<Control^>^temp5 = {this->listView1};
      this->Controls->AddRange( temp5 );
      this->Name = "ListViewSortForm";
      this->Text = "Sorted ListView Control";

      // Resume lay[Out] of* the form.
      this->ResumeLayout( false );
   }

private:

   // ColumnClick event handler.
   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 = gcnew ListViewItemComparer( e->Column );
   }
};

[System::STAThreadAttribute]
int main()
{
   Application::Run( gcnew ListViewSortForm );
}
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);
        }
    }
}
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Collections


Namespace ListViewSortFormNamespace

    Public Class ListViewSortForm
        Inherits Form

        Private listView1 As ListView

        Public Sub New()
            ' Create ListView items to add to the control.
            Dim listViewItem1 As New ListViewItem(New String() {"Banana", "a", "b", "c"}, -1, Color.Empty, Color.Yellow, Nothing)
            Dim listViewItem2 As New ListViewItem(New String() {"Cherry", "v", "g", "t"}, -1, Color.Empty, Color.Red, New Font("Microsoft Sans Serif", 8.25F, FontStyle.Regular, GraphicsUnit.Point, CType(0, System.Byte)))
            Dim listViewItem3 As New ListViewItem(New String() {"Apple", "h", "j", "n"}, -1, Color.Empty, Color.Lime, Nothing)
            Dim listViewItem4 As New ListViewItem(New String() {"Pear", "y", "u", "i"}, -1, Color.Empty, Color.FromArgb(CType(192, System.Byte), CType(128, System.Byte), CType(156, System.Byte)), Nothing)

            'Initialize the ListView control and add columns to it.
            Me.listView1 = New ListView

            ' Set the initial sorting type for the ListView.
            Me.listView1.Sorting = SortOrder.None
            ' Disable automatic sorting to enable manual sorting.
            Me.listView1.View = View.Details
            ' Add columns and set their text.
            Me.listView1.Columns.Add(New ColumnHeader)
            Me.listView1.Columns(0).Text = "Column 1"
            Me.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.
            Me.SuspendLayout()
            ' Add Items to the ListView control.
            Me.listView1.Items.AddRange(New ListViewItem() {listViewItem1, listViewItem2, listViewItem3, listViewItem4})
            ' Set the location and size of the ListView control.
            Me.listView1.Location = New Point(10, 10)
            Me.listView1.Name = "listView1"
            Me.listView1.Size = New Size(300, 100)
            Me.listView1.TabIndex = 0
            ' Enable editing of the items in the ListView.
            Me.listView1.LabelEdit = True
            ' Connect the ListView.ColumnClick event to the ColumnClick event handler.
            AddHandler Me.listView1.ColumnClick, AddressOf ColumnClick

            ' Initialize the form.
            Me.ClientSize = New Size(400, 400)
            Me.Controls.AddRange(New Control() {Me.listView1})
            Me.Name = "ListViewSortForm"
            Me.Text = "Sorted ListView Control"
            ' Resume layout of the form.
            Me.ResumeLayout(False)
        End Sub


        ' ColumnClick event handler.
        Private Sub ColumnClick(ByVal o As Object, ByVal e As ColumnClickEventArgs)
            ' Set the ListViewItemSorter property to a new ListViewItemComparer 
            ' object. Setting this property immediately sorts the 
            ' ListView using the ListViewItemComparer object.
            Me.listView1.ListViewItemSorter = New ListViewItemComparer(e.Column)
        End Sub

    End Class

    ' Implements the manual sorting of items by columns.
    Class ListViewItemComparer
        Implements IComparer

        Private col As Integer

        Public Sub New()
            col = 0
        End Sub

        Public Sub New(ByVal column As Integer)
            col = column
        End Sub

        Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer _
           Implements IComparer.Compare
            Return [String].Compare(CType(x, ListViewItem).SubItems(col).Text, CType(y, ListViewItem).SubItems(col).Text)
        End Function
    End Class
End Namespace

See also

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

用指定的子项、图像和组初始化 ListViewItem 类的新实例。Initializes a new instance of the ListViewItem class with the specified subitems, image, and group.

public:
 ListViewItem(cli::array <System::Windows::Forms::ListViewItem::ListViewSubItem ^> ^ subItems, System::String ^ imageKey, System::Windows::Forms::ListViewGroup ^ group);
public ListViewItem (System.Windows.Forms.ListViewItem.ListViewSubItem[] subItems, string imageKey, System.Windows.Forms.ListViewGroup group);
new System.Windows.Forms.ListViewItem : System.Windows.Forms.ListViewItem.ListViewSubItem[] * string * System.Windows.Forms.ListViewGroup -> System.Windows.Forms.ListViewItem
Public Sub New (subItems As ListViewItem.ListViewSubItem(), imageKey As String, group As ListViewGroup)

Parameters

subItems
ListViewItem.ListViewSubItem[]

ListViewItem.ListViewSubItem 对象的数组,表示 ListViewItem 的子项。An array of ListViewItem.ListViewSubItem objects that represent the subitems of the ListViewItem.

imageKey
String

所属 ImageListListView 中的图像的名称,将在该项中显示该名称。The name of the image within the ImageList of the owning ListView to display in the item.

group
ListViewGroup

要将项分配到的 ListViewGroupThe ListViewGroup to assign the item to.

Remarks

当你在将 ListViewItem.ListViewSubItem 对象添加到 ListViewItem 之前创建对象(例如,指示特殊格式或在多个项中使用子项)时,此版本的构造函数很有用。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.

imageKey 参数在与拥有的 ListView 控件关联的 ImageList 中指定一个图像,该图像可使用 ImageList 属性进行访问。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 组仅适用于 Windows XP 和 Windows Server 2003 家族(Windows XP Home Edition、Windows XP Professional、Windows Server 2003Windows XP Home Edition, Windows XP Professional, Windows Server 2003)。ListView groups are only available on Windows XP and the Windows Server 2003 family (Windows XP Home Edition、Windows XP Professional、Windows Server 2003Windows XP Home Edition, Windows XP Professional, Windows Server 2003). 有关更多信息,请参见 ListViewGroup 概述主题。For more information, see the ListViewGroup overview topic.

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

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

public:
 ListViewItem(cli::array <System::Windows::Forms::ListViewItem::ListViewSubItem ^> ^ subItems, int imageIndex, System::Windows::Forms::ListViewGroup ^ group);
public ListViewItem (System.Windows.Forms.ListViewItem.ListViewSubItem[] subItems, int imageIndex, System.Windows.Forms.ListViewGroup group);
new System.Windows.Forms.ListViewItem : System.Windows.Forms.ListViewItem.ListViewSubItem[] * int * System.Windows.Forms.ListViewGroup -> System.Windows.Forms.ListViewItem
Public Sub New (subItems As ListViewItem.ListViewSubItem(), imageIndex As Integer, group As ListViewGroup)

Parameters

subItems
ListViewItem.ListViewSubItem[]

ListViewItem.ListViewSubItem 类型的数组,表示该项的子项。An array of type ListViewItem.ListViewSubItem that represents the subitems of the item.

imageIndex
Int32

图像的从零开始的索引,该图像位于与包含该项的 ImageList 关联的 ListView 中。The zero-based index of the image within the ImageList associated with the ListView that contains the item.

group
ListViewGroup

要将项分配到的 ListViewGroupThe ListViewGroup to assign the item to.

Remarks

当你在将 ListViewItem.ListViewSubItem 对象添加到 ListViewItem 对象之前创建这些对象时,此版本的构造函数很有用(例如,指示特殊格式或使用多个项中的子项)。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 组仅适用于 Windows XP 和 Windows Server 2003 家族(Windows XP Home Edition、Windows XP Professional、Windows Server 2003Windows XP Home Edition, Windows XP Professional, Windows Server 2003)。ListView groups are only available on Windows XP and the Windows Server 2003 family (Windows XP Home Edition、Windows XP Professional、Windows Server 2003Windows XP Home Edition, Windows XP Professional, Windows Server 2003). 有关更多信息,请参见 ListViewGroup 概述主题。For more information, see the ListViewGroup overview topic.

See also

ListViewItem(String[], String, ListViewGroup)

用包含指定文本、图像和组的子项初始化 ListViewItem 类的新实例。Initializes a new instance of the ListViewItem class with subitems containing the specified text, image, and group.

public:
 ListViewItem(cli::array <System::String ^> ^ items, System::String ^ imageKey, System::Windows::Forms::ListViewGroup ^ group);
public ListViewItem (string[] items, string imageKey, System.Windows.Forms.ListViewGroup group);
new System.Windows.Forms.ListViewItem : string[] * string * System.Windows.Forms.ListViewGroup -> System.Windows.Forms.ListViewItem
Public Sub New (items As String(), imageKey As String, group As ListViewGroup)

Parameters

items
String[]

一个字符串数组,表示 ListViewItem 的子项的文本。An array of strings that represents the text for subitems of the ListViewItem.

imageKey
String

所属 ImageListListView 中的图像的名称,将在该项中显示该名称。The name of the image within the ImageList of the owning ListView to display in the item.

group
ListViewGroup

要将项分配到的 ListViewGroupThe ListViewGroup to assign the item to.

Remarks

此版本的构造函数允许您指定项所属的组。This version of the constructor allows you to specify the group to which an item belongs.

imageKey 参数在与拥有的 ListView 控件关联的 ImageList 中指定一个图像,该图像可使用 ImageList 属性进行访问。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 组仅适用于 Windows XP 和 Windows Server 2003 家族(Windows XP Home Edition、Windows XP Professional、Windows Server 2003Windows XP Home Edition, Windows XP Professional, Windows Server 2003)。ListView groups are only available on Windows XP and the Windows Server 2003 family (Windows XP Home Edition、Windows XP Professional、Windows Server 2003Windows XP Home Edition, Windows XP Professional, Windows Server 2003). 有关更多信息,请参见 ListViewGroup 概述主题。For more information, see the ListViewGroup overview topic.

ListViewItem(String[], Int32, ListViewGroup)

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

public:
 ListViewItem(cli::array <System::String ^> ^ items, int imageIndex, System::Windows::Forms::ListViewGroup ^ group);
public ListViewItem (string[] items, int imageIndex, System.Windows.Forms.ListViewGroup group);
new System.Windows.Forms.ListViewItem : string[] * int * System.Windows.Forms.ListViewGroup -> System.Windows.Forms.ListViewItem
Public Sub New (items As String(), imageIndex As Integer, group As ListViewGroup)

Parameters

items
String[]

表示此新项的子项的字符串数组。An array of strings that represent the subitems of the new item.

imageIndex
Int32

图像的从零开始的索引,该图像位于与包含该项的 ImageList 关联的 ListView 中。The zero-based index of the image within the ImageList associated with the ListView that contains the item.

group
ListViewGroup

要将项分配到的 ListViewGroupThe 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 组仅适用于 Windows XP 和 Windows Server 2003 家族(Windows XP Home Edition、Windows XP Professional、Windows Server 2003Windows XP Home Edition, Windows XP Professional, Windows Server 2003)。ListView groups are only available on Windows XP and the Windows Server 2003 family (Windows XP Home Edition、Windows XP Professional、Windows Server 2003Windows XP Home Edition, Windows XP Professional, Windows Server 2003). 有关更多信息,请参见 ListViewGroup 概述主题。For more information, see the ListViewGroup overview topic.

See also

ListViewItem(String, String, ListViewGroup)

用指定的文本、图像和组初始化 ListViewItem 类的新实例。Initializes a new instance of the ListViewItem class with the specified text, image, and group.

public:
 ListViewItem(System::String ^ text, System::String ^ imageKey, System::Windows::Forms::ListViewGroup ^ group);
public ListViewItem (string text, string imageKey, System.Windows.Forms.ListViewGroup group);
new System.Windows.Forms.ListViewItem : string * string * System.Windows.Forms.ListViewGroup -> System.Windows.Forms.ListViewItem
Public Sub New (text As String, imageKey As String, group As ListViewGroup)

Parameters

text
String

要为该项显示的文本。The text to display for the item. 该文本不应该超过 259 个字符。This should not exceed 259 characters.

imageKey
String

所属 ImageListListView 中的图像的名称,将在该项中显示该名称。The name of the image within the ImageList of the owning ListView to display in the item.

group
ListViewGroup

要将项分配到的 ListViewGroupThe ListViewGroup to assign the item to.

Remarks

此版本的构造函数允许您指定项所属的组。This version of the constructor allows you to specify the group to which an item belongs.

imageKey 参数在与拥有的 ListView 控件关联的 ImageList 中指定一个图像,该图像可使用 ImageList 属性进行访问。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 组仅适用于 Windows XP 和 Windows Server 2003 家族(Windows XP Home Edition、Windows XP Professional、Windows Server 2003Windows XP Home Edition, Windows XP Professional, Windows Server 2003)。ListView groups are only available on Windows XP and the Windows Server 2003 family (Windows XP Home Edition、Windows XP Professional、Windows Server 2003Windows XP Home Edition, Windows XP Professional, Windows Server 2003). 有关更多信息,请参见 ListViewGroup 概述主题。For more information, see the ListViewGroup overview topic.

ListViewItem 的文本不应超过259个字符,否则可能会发生意外行为。The text of the ListViewItem should not exceed 259 characters or unexpected behavior could occur.

ListViewItem(ListViewItem+ListViewSubItem[], String)

用指定的子项和图像初始化 ListViewItem 类的新实例。Initializes a new instance of the ListViewItem class with the specified subitems and image.

public:
 ListViewItem(cli::array <System::Windows::Forms::ListViewItem::ListViewSubItem ^> ^ subItems, System::String ^ imageKey);
public ListViewItem (System.Windows.Forms.ListViewItem.ListViewSubItem[] subItems, string imageKey);
new System.Windows.Forms.ListViewItem : System.Windows.Forms.ListViewItem.ListViewSubItem[] * string -> System.Windows.Forms.ListViewItem
Public Sub New (subItems As ListViewItem.ListViewSubItem(), imageKey As String)

Parameters

imageKey
String

所属 ImageListListView 中的图像的名称,将在 ListViewItem 中显示该名称。The name of the image within the ImageList of the owning ListView to display in the ListViewItem.

Remarks

imageKey 参数在与拥有的 ListView 控件关联的 ImageList 中指定一个图像,该图像可使用 ImageList 属性进行访问。The imageKey parameter specifies an image in the ImageList associated with the owning ListView control, which can be accessed with the ImageList property.

ListViewItem(String, Int32, ListViewGroup)

用指定的项文本和项图标的图像索引位置初始化 ListViewItem 类的新实例,并将该项分配到指定的组。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.

public:
 ListViewItem(System::String ^ text, int imageIndex, System::Windows::Forms::ListViewGroup ^ group);
public ListViewItem (string text, int imageIndex, System.Windows.Forms.ListViewGroup group);
new System.Windows.Forms.ListViewItem : string * int * System.Windows.Forms.ListViewGroup -> System.Windows.Forms.ListViewItem
Public Sub New (text As String, imageIndex As Integer, group As ListViewGroup)

Parameters

text
String

要为该项显示的文本。The text to display for the item. 该文本不应该超过 259 个字符。This should not exceed 259 characters.

imageIndex
Int32

图像的从零开始的索引,该图像位于与包含该项的 ImageList 关联的 ListView 中。The zero-based index of the image within the ImageList associated with the ListView that contains the item.

group
ListViewGroup

要将项分配到的 ListViewGroupThe 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 组仅适用于 Windows XP 和 Windows Server 2003 家族(Windows XP Home Edition、Windows XP Professional、Windows Server 2003Windows XP Home Edition, Windows XP Professional, Windows Server 2003)。ListView groups are only available on Windows XP and the Windows Server 2003 family (Windows XP Home Edition、Windows XP Professional、Windows Server 2003Windows XP Home Edition, Windows XP Professional, Windows Server 2003). 有关更多信息,请参见 ListViewGroup 概述主题。For more information, see the ListViewGroup overview topic.

ListViewItem 的文本不应超过259个字符,否则可能会发生意外行为。The text of the ListViewItem should not exceed 259 characters or unexpected behavior could occur.

See also

ListViewItem(String[], ListViewGroup)

用表示子项的字符串数组初始化 ListViewItem 类的新实例,并将该项分配到指定的组。Initializes a new instance of the ListViewItem class with an array of strings representing subitems, and assigns the item to the specified group.

public:
 ListViewItem(cli::array <System::String ^> ^ items, System::Windows::Forms::ListViewGroup ^ group);
public ListViewItem (string[] items, System.Windows.Forms.ListViewGroup group);
new System.Windows.Forms.ListViewItem : string[] * System.Windows.Forms.ListViewGroup -> System.Windows.Forms.ListViewItem
Public Sub New (items As String(), group As ListViewGroup)

Parameters

items
String[]

表示此新项的子项的字符串数组。An array of strings that represent the subitems of the new item.

group
ListViewGroup

要将项分配到的 ListViewGroupThe 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 组仅适用于 Windows XP 和 Windows Server 2003 家族(Windows XP Home Edition、Windows XP Professional、Windows Server 2003Windows XP Home Edition, Windows XP Professional, Windows Server 2003)。ListView groups are only available on Windows XP and the Windows Server 2003 family (Windows XP Home Edition、Windows XP Professional、Windows Server 2003Windows XP Home Edition, Windows XP Professional, Windows Server 2003). 有关更多信息,请参见 ListViewGroup 概述主题。For more information, see the ListViewGroup overview topic.

See also

ListViewItem(String[], String)

用指定的项和子项文本及图像初始化 ListViewItem 类的新实例。Initializes a new instance of the ListViewItem class with the specified item and subitem text and image.

public:
 ListViewItem(cli::array <System::String ^> ^ items, System::String ^ imageKey);
public ListViewItem (string[] items, string imageKey);
new System.Windows.Forms.ListViewItem : string[] * string -> System.Windows.Forms.ListViewItem
Public Sub New (items As String(), imageKey As String)

Parameters

items
String[]

一个数组,它包含 ListViewItem 的子项的文本。An array containing the text of the subitems of the ListViewItem.

imageKey
String

所属 ImageListListView 中的图像的名称,将在 ListViewItem 中显示该名称。The name of the image within the ImageList of the owning ListView to display in the ListViewItem.

Remarks

imageKey 参数在与拥有的 ListView 控件关联的 ImageList 中指定一个图像,该图像可使用 ImageList 属性进行访问。The imageKey parameter specifies an image in the ImageList associated with the owning ListView control, which can be accessed with the ImageList property.

ListViewItem(String[], Int32)

用项图标的图像索引位置和表示子项的字符串数组初始化 ListViewItem 类的新实例。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.

public:
 ListViewItem(cli::array <System::String ^> ^ items, int imageIndex);
public ListViewItem (string[] items, int imageIndex);
new System.Windows.Forms.ListViewItem : string[] * int -> System.Windows.Forms.ListViewItem
Public Sub New (items As String(), imageIndex As Integer)

Parameters

items
String[]

表示此新项的子项的字符串数组。An array of strings that represent the subitems of the new item.

imageIndex
Int32

图像的从零开始的索引,该图像位于与包含该项的 ImageList 关联的 ListView 中。The zero-based index of the image within the ImageList associated with the ListView that contains the item.

See also

ListViewItem(String, ListViewGroup)

用指定的项文本初始化 ListViewItem 类的新实例,并将它分配到指定的组。Initializes a new instance of the ListViewItem class with the specified item text and assigns it to the specified group.

public:
 ListViewItem(System::String ^ text, System::Windows::Forms::ListViewGroup ^ group);
public ListViewItem (string text, System.Windows.Forms.ListViewGroup group);
new System.Windows.Forms.ListViewItem : string * System.Windows.Forms.ListViewGroup -> System.Windows.Forms.ListViewItem
Public Sub New (text As String, group As ListViewGroup)

Parameters

text
String

要为该项显示的文本。The text to display for the item. 该文本不应该超过 259 个字符。This should not exceed 259 characters.

group
ListViewGroup

要将项分配到的 ListViewGroupThe 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 组仅适用于 Windows XP 和 Windows Server 2003 家族(Windows XP Home Edition、Windows XP Professional、Windows Server 2003Windows XP Home Edition, Windows XP Professional, Windows Server 2003)。ListView groups are only available on Windows XP and the Windows Server 2003 family (Windows XP Home Edition、Windows XP Professional、Windows Server 2003Windows XP Home Edition, Windows XP Professional, Windows Server 2003). 有关更多信息,请参见 ListViewGroup 概述主题。For more information, see the ListViewGroup overview topic.

ListViewItem 的文本不应超过259个字符,否则可能会发生意外行为。The text of the ListViewItem should not exceed 259 characters or unexpected behavior could occur.

See also

ListViewItem(String, String)

用指定的文本和图像初始化 ListViewItem 类的新实例。Initializes a new instance of the ListViewItem class with the specified text and image.

public:
 ListViewItem(System::String ^ text, System::String ^ imageKey);
public ListViewItem (string text, string imageKey);
new System.Windows.Forms.ListViewItem : string * string -> System.Windows.Forms.ListViewItem
Public Sub New (text As String, imageKey As String)

Parameters

text
String

要为该项显示的文本。The text to display for the item. 该文本不应该超过 259 个字符。This should not exceed 259 characters.

imageKey
String

所属 ImageListListView 中的图像的名称,将在 ListViewItem 中显示该名称。The name of the image within the ImageList of the owning ListView to display in the ListViewItem.

Remarks

imageKey 参数在与拥有的 ListView 控件关联的 ImageList 中指定一个图像,该图像可使用 ImageList 属性进行访问。The imageKey parameter specifies an image in the ImageList associated with the owning ListView control, which can be accessed with the ImageList property.

ListViewItem 的文本不应超过259个字符,否则可能会发生意外行为。The text of the ListViewItem should not exceed 259 characters or unexpected behavior could occur.

ListViewItem(String, Int32)

用指定的项文本和项图标的图像索引位置初始化 ListViewItem 类的新实例。Initializes a new instance of the ListViewItem class with the specified item text and the image index position of the item's icon.

public:
 ListViewItem(System::String ^ text, int imageIndex);
public ListViewItem (string text, int imageIndex);
new System.Windows.Forms.ListViewItem : string * int -> System.Windows.Forms.ListViewItem
Public Sub New (text As String, imageIndex As Integer)

Parameters

text
String

要为该项显示的文本。The text to display for the item. 该文本不应该超过 259 个字符。This should not exceed 259 characters.

imageIndex
Int32

图像的从零开始的索引,该图像位于与包含该项的 ImageList 关联的 ListView 中。The zero-based index of the image within the ImageList associated with the ListView that contains the item.

Remarks

ListViewItem 的文本不应超过259个字符,否则可能会发生意外行为。The text of the ListViewItem should not exceed 259 characters or unexpected behavior could occur.

See also

ListViewItem(SerializationInfo, StreamingContext)

使用指定的序列化信息和流上下文初始化 ListViewItem 类的新实例。Initializes a new instance of the ListViewItem class with the specified serialization information and streaming context.

protected:
 ListViewItem(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
protected ListViewItem (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
new System.Windows.Forms.ListViewItem : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Windows.Forms.ListViewItem
Protected Sub New (info As SerializationInfo, context As StreamingContext)

Parameters

info
SerializationInfo

一个 SerializationInfo,包含关于要初始化的 ListViewItem 的信息。A SerializationInfo containing information about the ListViewItem to be initialized.

context
StreamingContext

一个 StreamingContext,指示序列化的流的源和目标以及上下文信息。A StreamingContext that indicates the source destination and context information of a serialized stream.

ListViewItem(ListViewGroup)

初始化 ListViewItem 类的新实例,并将它分配到指定的组。Initializes a new instance of the ListViewItem class and assigns it to the specified group.

public:
 ListViewItem(System::Windows::Forms::ListViewGroup ^ group);
public ListViewItem (System.Windows.Forms.ListViewGroup group);
new System.Windows.Forms.ListViewItem : System.Windows.Forms.ListViewGroup -> System.Windows.Forms.ListViewItem
Public Sub New (group As ListViewGroup)

Parameters

group
ListViewGroup

要将项分配到的 ListViewGroupThe 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 组仅适用于 Windows XP 和 Windows Server 2003 家族(Windows XP Home Edition、Windows XP Professional、Windows Server 2003Windows XP Home Edition, Windows XP Professional, Windows Server 2003)。ListView groups are only available on Windows XP and the Windows Server 2003 family (Windows XP Home Edition、Windows XP Professional、Windows Server 2003Windows XP Home Edition, Windows XP Professional, Windows Server 2003). 有关更多信息,请参见 ListViewGroup 概述主题。For more information, see the ListViewGroup overview topic.

See also

ListViewItem(String[])

用表示子项的字符串数组初始化 ListViewItem 类的新实例。Initializes a new instance of the ListViewItem class with an array of strings representing subitems.

public:
 ListViewItem(cli::array <System::String ^> ^ items);
public ListViewItem (string[] items);
new System.Windows.Forms.ListViewItem : string[] -> System.Windows.Forms.ListViewItem
Public Sub New (items As String())

Parameters

items
String[]

表示此新项的子项的字符串数组。An array of strings that represent the subitems of the new item.

ListViewItem(String)

用指定的项文本初始化 ListViewItem 类的新实例。Initializes a new instance of the ListViewItem class with the specified item text.

public:
 ListViewItem(System::String ^ text);
public ListViewItem (string text);
new System.Windows.Forms.ListViewItem : string -> System.Windows.Forms.ListViewItem
Public Sub New (text As String)

Parameters

text
String

要为该项显示的文本。The text to display for the item. 该文本不应该超过 259 个字符。This should not exceed 259 characters.

Remarks

ListViewItem 的文本不应超过259个字符,否则可能会发生意外行为。The text of the ListViewItem should not exceed 259 characters or unexpected behavior could occur.

ListViewItem(ListViewItem+ListViewSubItem[], Int32)

用项图标的图像索引位置和 ListViewItem 对象的数组初始化 ListViewItem.ListViewSubItem 类的新实例。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.

public:
 ListViewItem(cli::array <System::Windows::Forms::ListViewItem::ListViewSubItem ^> ^ subItems, int imageIndex);
public ListViewItem (System.Windows.Forms.ListViewItem.ListViewSubItem[] subItems, int imageIndex);
new System.Windows.Forms.ListViewItem : System.Windows.Forms.ListViewItem.ListViewSubItem[] * int -> System.Windows.Forms.ListViewItem
Public Sub New (subItems As ListViewItem.ListViewSubItem(), imageIndex As Integer)

Parameters

subItems
ListViewItem.ListViewSubItem[]

ListViewItem.ListViewSubItem 类型的数组,表示该项的子项。An array of type ListViewItem.ListViewSubItem that represents the subitems of the item.

imageIndex
Int32

图像的从零开始的索引,该图像位于与包含该项的 ImageList 关联的 ListView 中。The zero-based index of the image within the ImageList associated with the ListView that contains the item.

Remarks

当你在将 ListViewItem.ListViewSubItem 对象添加到 ListViewItem 之前创建对象(例如,指示特殊格式或在多个项中使用子项)时,此版本的构造函数很有用。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