Skip to main content

Tutorial: Create and Manage Columns at Design Time

  • 2 minutes to read

This tutorial explains how to do the following in the Grid Designer:

  • Create a column and bind it to a data field.

  • Create columns for all data fields in the data source.

  • Remove a column.

Watch Video: Create and Manage Columns at Design Time

Starting Point

Start with a project that has a Data Grid bound to a data source. This tutorial uses the Products table from the Northwind database as the data source.

Bound data source Products table Northwind database

Default Behavior

When you bind the Data Grid to a data source, the Data Grid creates columns for all data fields in the data source if the View’s Columns collection is empty.

WinForms Data Grid bound to Products table Northwind database

Manage the Column Collection

Use the Grid Designer to add/remove a column, reorder or otherwise manage the column collection.

WinForms Data Grid open Grid Designer

The Columns tab displays the following sections:

  • Field List - lists data fields in the bound data source. Data fields in bold font do not have a bound column.

  • Columns - lists the Grid View’s columns.

  • Column properties - lists column properties.

WinForms Data Grid Designer Columns tab

Create Bound Columns

Drag a data field to the Columns list to create a column bound to this data field.

WinForms Data Grid drag field to create bound column in Grid Designer

Create and Bind Columns Manually

  1. Click “Add Column” above the Columns list.

    WinForms Data Grid create column manually in Grid Designer

  2. Use the GridColumn.Name property to change the column’s name.

    WinForms Data Grid modify column name in Grid Designer

  3. Use the GridColumn.FieldName property to bind the column to a data field.

    WinForms Data Grid bind column to data field in Grid Designer

Tip

To insert a column at a specific position, select a column in the Columns list and click “Insert Column” above the Columns list.

Create Columns for All Data Fields

The “Retrieve Fields” button clears the column collection and creates a bound column for every data field in the data source.

WinForms Data Grid Retrieve Fields button in Grid Designer

Remove Columns

Select a column in the Columns list and click “Remove Column”.

WinForms Data Grid remove column in Grid Designer

See Also