DataGridView.Columns Property

 

Gets a collection that contains all the columns in the control.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

member Columns : DataGridViewColumnCollection with get

Property Value

Type: System.Windows.Forms.DataGridViewColumnCollection

The DataGridViewColumnCollection that contains all the columns in the DataGridView control.

By using the DataGridViewColumnCollection returned by this property, you can add columns, remove columns, and obtain a count of the columns contained in the DataGridView control. For more information, see DataGridViewColumnCollection.

The following code example demonstrates how to create an unbound DataGridView; set the ColumnHeadersVisible, ColumnHeadersDefaultCellStyle, and ColumnCount properties; and use the Rows and Columns properties. It also demonstrates how to use a version of the AutoResizeColumnHeadersHeight and AutoResizeRows methods to properly size the column headers and the rows. To run this example, paste the following code into a form that contains a DataGridView named dataGridView1 and a button named Button1, and then call the InitializeDataGridView method from the form's constructor or Load event handler. Ensure all events are connected with their event handlers.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 2.0
Return to top
Show: