다음을 통해 공유


How to: Add Columns to the Windows Forms ListView Control

In the Details view, the ListView control can display multiple columns for each list item. You can use the columns to display to the user several types of information about each list item. For example, a list of files could display the file name, file type, size, and date the file was last modified. For information about populating the columns after they are created, see How to: Display Subitems in Columns with the Windows Forms ListView Control.

To add columns programmatically

  1. Set the control's View property to Details.

  2. Use the Add method of the list view's Columns property.

    ' Set to details view
    ListView1.View = View.Details
    ' Add a column with width 20 and left alignment
    ListView1.Columns.Add("File type", 20, HorizontalAlignment.Left)
    
    // Set to details view.
    listView1.View = View.Details;
    // Add a column with width 20 and left alignment.
    listView1.Columns.Add("File type", 20, HorizontalAlignment.Left);
    
    // Set to details view.
    listView1.set_View(View.Details);
    // Add a column with width 20 and left alignment.
    listView1.get_Columns().Add("File type", 20, HorizontalAlignment.Left);
    

See Also

Reference

ListView Control Overview (Windows Forms)
ListView

Other Resources

ListView Control (Windows Forms)