다음을 통해 공유


How to: Display Subitems in Columns with the Windows Forms ListView Control

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 How to: Add Columns to the Windows Forms ListView Control.

  2. Call the Add method of the collection returned by the SubItems property of an item. The code example below sets the employee name and department for a list item.

    ' Adds two subitems to the first list item
    ListView1.Items(0).SubItems.Add("John Smith")
    ListView1.Items(0).SubItems.Add("Accounting")
    
    // Adds two subitems to the first list item.
    listView1.Items[0].SubItems.Add("John Smith");
    listView1.Items[0].SubItems.Add("Accounting");
    
    // Adds two subitems to the first list item.
    listView1.get_Items().get_Item(0).get_SubItems().Add("John Smith");
    listView1.get_Items().get_Item(0).get_SubItems().Add("Accounting");
    

See Also

Tasks

How to: Add and Remove Items with the Windows Forms ListView Control
How to: Add Columns to the Windows Forms ListView Control
How to: Display Icons for the Windows Forms ListView Control
How to: Add Custom Information to a TreeView or ListView Control (Windows Forms)

Reference

ListView Control Overview (Windows Forms)