---
title: Remove Autogenerated Columns from DataGridView Control
ms.date: "03/30/2017"
dev_langs: 
  - "csharp"
  - "vb"
helpviewer_keywords: 
  - "DataGridView control [Windows Forms], removing columns"
  - "columns [Windows Forms], removing"
ms.assetid: 92e28d98-95a3-446c-9150-41b7c7e5be15
---
# How to: Remove Autogenerated Columns from a Windows Forms DataGridView Control
When your <xref:System.Windows.Forms.DataGridView> control 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 <xref:System.Windows.Forms.DataGridViewColumnCollection.Remove%2A> method on the <xref:System.Windows.Forms.DataGridView.Columns%2A> collection. Alternatively, you can hide columns from view by setting the <xref:System.Windows.Forms.DataGridViewColumn.Visible%2A> 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 <xref:System.Windows.Forms.DataGridViewColumnCollection.Remove%2A> method on the <xref:System.Windows.Forms.DataGridView.Columns%2A> collection.  
  
     [!code-csharp[System.Windows.Forms.DataGridViewMisc#111](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Windows.Forms.DataGridViewMisc/CS/datagridviewmisc.cs#111)]
     [!code-vb[System.Windows.Forms.DataGridViewMisc#111](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.DataGridViewMisc/VB/datagridviewmisc.vb#111)]  
  
### To hide autogenerated columns  
  
- Set the column's <xref:System.Windows.Forms.DataGridViewColumn.Visible%2A> property to `false`.  
  
     [!code-csharp[System.Windows.Forms.DataGridViewMisc#112](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Windows.Forms.DataGridViewMisc/CS/datagridviewmisc.cs#112)]
     [!code-vb[System.Windows.Forms.DataGridViewMisc#112](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.DataGridViewMisc/VB/datagridviewmisc.vb#112)]  
  
## Example  
 [!code-csharp[System.Windows.Forms.DataGridViewMisc#110](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Windows.Forms.DataGridViewMisc/CS/datagridviewmisc.cs#110)]
 [!code-vb[System.Windows.Forms.DataGridViewMisc#110](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.DataGridViewMisc/VB/datagridviewmisc.vb#110)]  
  
## Compiling the Code  
 This example requires:  
  
- A <xref:System.Windows.Forms.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 the <xref:System?displayProperty=nameWithType> and <xref:System.Windows.Forms?displayProperty=nameWithType> assemblies.  
  
## See also

- <xref:System.Windows.Forms.DataGridView>
- <xref:System.Windows.Forms.DataGridView.AutoGenerateColumns%2A?displayProperty=nameWithType>
- <xref:System.Windows.Forms.DataGridView.Columns%2A?displayProperty=nameWithType>
- <xref:System.Windows.Forms.DataGridViewColumnCollection.Remove%2A?displayProperty=nameWithType>
- <xref:System.Windows.Forms.DataGridViewColumn.Visible%2A?displayProperty=nameWithType>
- [Displaying Data in the Windows Forms DataGridView Control](displaying-data-in-the-windows-forms-datagridview-control.md)
