Export (0) Print
Expand All

Displaying Subitems in Columns with the Windows Forms ListView Control

Visual Studio .NET 2003

The Windows Forms ListView control can display additional text, or subitems, for each item in the Details view. The first column displays the item text, for example an employee number. The second, third, and subsequent columns display the first, second, and subsequent associated subitems.

To add subitems to a list item

  1. Add any columns needed. Because the first column will display the item's Text property, you need one more column than there are subitems. For more information on adding columns, see Adding Columns to the Windows Forms ListView Control.
  2. Call the SetSubItem method of the Items property. The code example below sets the employee name and department for a list item.
    ' Visual Basic
    ' Adds two subitems to the first list item
    ListView1.Items(0).SubItems.Add("John Smith")
    ListView1.Items(0).SubItems.Add("Accounting")
    
    // C#
    // Adds two subitems to the first list item.
    listView1.Items[0].SubItems.Add("John Smith");
    listView1.Items[0].SubItems.Add("Accounting");
    
    // C++
    // Adds two subitems to the first list item.
    listView1->Items->Item[0]->SubItems->Add(S"John Smith");
    listView1->Items->Item[0]->SubItems->Add(S"Accounting");
    

See Also

Introduction to the Windows Forms ListView Control | Adding and Removing Items with the Windows Forms ListView Control | Adding Columns to the Windows Forms ListView Control | Displaying Icons for the Windows Forms ListView Control | Adding Custom Information to a TreeView or ListView Control (Windows Forms)

Show:
© 2014 Microsoft