DataGridView.Columns Property
Gets a collection that contains all the columns in the control.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Property Value
Type: System.Windows.Forms.DataGridViewColumnCollectionThe 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.
Available since 2.0