Training
Module
Create and manage columns within a table in Microsoft Dataverse - Training
Learn how to create and manage table columns in Dataverse.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
When your 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 Remove method on the Columns collection. Alternatively, you can hide columns from view by setting the Visible 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.
Call the Remove method on the Columns collection.
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = customersDataSet;
dataGridView1.Columns.Remove("Fax");
With dataGridView1
.AutoGenerateColumns = True
.DataSource = customersDataSet
.Columns.Remove("Fax")
End With
Set the column's Visible property to false
.
dataGridView1.Columns["CustomerID"].Visible = false;
dataGridView1.Columns("CustomerID").Visible = False
private void BindDataAndInitializeColumns()
{
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = customersDataSet;
dataGridView1.Columns.Remove("Fax");
dataGridView1.Columns["CustomerID"].Visible = false;
}
Private Sub BindDataAndInitializeColumns()
With dataGridView1
.AutoGenerateColumns = True
.DataSource = customersDataSet
.Columns.Remove("Fax")
.Columns("CustomerID").Visible = False
End With
End Sub
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 the System and System.Windows.Forms assemblies.
.NET Desktop feedback feedback
.NET Desktop feedback is an open source project. Select a link to provide feedback:
Training
Module
Create and manage columns within a table in Microsoft Dataverse - Training
Learn how to create and manage table columns in Dataverse.
Documentation
Hide Columns in DataGridView Control - Windows Forms .NET Framework
Learn how to hide columns programmatically in the Windows Forms DataGridView control by setting the DataGridViewColumn.Visible property to false.
Get and Set the Current Cell in DataGridView Control - Windows Forms .NET Framework
Learn how to programmatically discover which cell is currently active by getting and setting the current cell in the Windows Forms DataGridView control.
Add an Unbound Column to a Data-Bound DataGridView Control - Windows Forms .NET Framework
Learn how to add an unbound column to a data-bound Windows Forms DataGridView control to display a column of data that does not come from the data source.