Share via


How to: Hide Columns in DataGridView Controls

You can hide columns in a DataGridView control programmatically or in the designer. Either way, you would set the Visible property of the column to false to hide it.

To hide a DataGridView column in the designer

  1. Add a DataGridView control by using the Customers table from the Northwind database, as described in How to: Display Data by Using DataGridView Controls.

  2. Click the ellipsis (…) button next to the Columns property.

    The Edit Columns dialog box opens.

  3. In the Edit Columns dialog box, select the second column (Company Name), then in the Bound Column Properties window, set the Visible property to False.

  4. Click OK to close the dialog box.

  5. Press F5 to run the code and verify that the Company Name column is hidden.

To hide a DataGridView column programmatically

  1. Double-click the column on the DataGridView control to add the default CellContentClick event handler, and then add the following code. This code hides the first column in the DataGridView control.

    this.customersDataGridView.Columns[0].Visible = false;
    
  2. Press F5 to run the code.

  3. Click inside the DataGridView control and verify that the Customer ID column is hidden.

See Also

Tasks

How to: Display Data by Using DataGridView Controls

How to: Sort Data in DataGridView Controls

Other Resources

Accessing and Displaying Data