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.
#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.
#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.
#Manage the Column Collection
Use the Grid Designer to add/remove a column, reorder or otherwise manage the column collection.
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.
#Create Bound Columns
Drag a data field to the Columns list to create a column bound to this data field.
#Create and Bind Columns Manually
Click “Add Column” above the Columns list.
Use the GridColumn.Name property to change the column’s name.
Use the GridColumn.FieldName property to bind the column to a data field.
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.
#Remove Columns
Select a column in the Columns list and click “Remove Column”.