How to: Hide Columns in the Windows Forms DataGridView Control

Sometimes you will want to display only some of the columns that are available in a Windows Forms DataGridView control. For example, you might want to show an employee salary column to users with management credentials while hiding it from other users. Alternately, you might want to bind the control to a data source that contains many columns, only some of which you want to display. In this case, you will typically remove the columns you are not interested in displaying rather than hide them.

In the DataGridView control, the Visible property value of a column determines whether that column is displayed.

There is support for this task in Visual Studio. Also see How to: Hide Columns in the Windows Forms DataGridView Control Using the Designer.

To hide a column programmatically

  • Set the DataGridViewColumn.Visible property to false. To hide a CustomerID column that is automatically generated during data binding, place the following code example in a DataBindingComplete event handler.

    this.dataGridView1.Columns["CustomerID"].Visible = false;
    
    Me.dataGridView1.Columns("CustomerID").Visible = False
    

Compiling the Code

This example requires:

See also