How to: Remove Autogenerated Columns from a Windows Forms DataGridView Control
When yourcontrol is set to autogenerate its columns based on data from its data source, you can selectively omit certain columns. You can do this by calling the method on the collection. Alternatively, you can hide columns from view by setting the property to false. This technique is useful when you want to display the hidden columns in certain conditions, or when you need to access the data in the columns without displaying it.
To remove autogenerated columns
Call the Remove method on the Columns collection.
To hide autogenerated columns
Set the column's Visible property to false.
Compiling the Code
This example requires:
A DataGridView control named dataGridView1 bound to a table that contains Fax and CustomerID columns, such as the Customers table in the Northwind sample database.
References to theand assemblies.