Skip to content

Latest commit

 

History

History
31 lines (24 loc) · 1.93 KB

how-to-add-columns-to-the-windows-forms-listview-control.md

File metadata and controls

31 lines (24 loc) · 1.93 KB
title description ms.date dev_langs helpviewer_keywords ms.assetid
Add Columns to ListView Control
Learn how to add columns to the Windows Forms ListView control to display several types of information about each list item.
03/30/2017
csharp
vb
ListView control [Windows Forms], adding column headers
columns [Windows Forms], adding to ListView controls
list views [Windows Forms], adding columns
79174274-12ee-4a5d-80db-6ec02976d010

How to: Add Columns to the Windows Forms ListView Control

In the Details view, the xref:System.Windows.Forms.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 xref:System.Windows.Forms.ListView.View%2A property to xref:System.Windows.Forms.View.Details.

  2. Use the xref:System.Windows.Forms.ListView.ColumnHeaderCollection.Add%2A method of the list view's xref:System.Windows.Forms.ListView.Columns%2A property.

    [!code-csharpSystem.Windows.Forms.ListViewLegacyTopics#31] [!code-vbSystem.Windows.Forms.ListViewLegacyTopics#31]

See also