Skip to main content
A newer version of this page is available. .


  • 6 minutes to read

Automatic Column Generation

When you bind a Data Grid to a data source, the control automatically generates a column for each found data field. For code-first data sources (e.g., Entity Framework models), you can mark a property with the Display attribute and disable its AutoGenerateField parameter to skip generating a column for this property. The “Display” attribute in the code below prevents a Data Grid from generating an “Additional Info” column.

[Display(AutoGenerateField = false, Description = "This column isn't created")]
public string AdditionalInfo { get; set; }

You can utilize many more attributes to re-arrange columns, modify captions of their headers, change their default in-place editors, etc. Refer to the Data Annotation Attributes article to learn more.

In case you have replaced a previous data source with a new one, the Data Grid will not automatically re-generate columns. You need to do that manually by invoking the Data Grid Designer and clicking the “Retrieve Fields” button within the “Columns” tab.

Data Grid - Retrieve Fields Designer

To do the same in code, call the BaseView.PopulateColumns method either directly after changing a data source, or on the GridControl.DataSourceChanged event.

See also: Obtaining Fields Available in Data Source.

Add and Remove Columns Manually

Columns associated with data fields declared in a data source are called bound columns. To add such columns manually, invoke the Data Grid designer, switch to the “Columns” tab and click the “Show Field List” button, then drag a data field into the column list. Data fields that have no corresponding grid columns are highlighted with bold text.

Data Grid - Add Bound Columns in Designer

You can also utilize the “Add Column” and “Insert Column” buttons on the same designer page. In this case, you need to set every column’s GridColumn.FieldName property manually. Otherwise, a column is unbound and does not receive cell values from a data source.

Data Grid - Add Columns Designer Buttons

To remove a column, utilize the “Remove Column” designer button, or click a column header at design time and press the “Delete” key.

Column Header

To modify a column header caption and add an image, select a column at design time and invoke its smart tag. If a column has no caption assigned, the column generates its caption based on the name of a related data field.

Data Grid - Column Smart Tag

Related API

Hide Vertical Column Borders

You can hide column and row borders by disabling the GridOptionsView.ShowVerticalLines and GridOptionsView.ShowHorizontalLines settings.

Data Grid - Vertical Lines

Column Width

By default, the Data Grid squeezes all its columns into its current client area. End-users can resize columns except for the last one and total column width cannot exceed the width of a parent View.

Data Grid - Auto Width

Disable the GridOptionsView.ColumnAutoWidth property to allow grid columns to transcend the View bounds. A horizontal scroll bar is displayed automatically if columns occupy more space than the View provides.

Data Grid - Disabled Auto Width

Related API

Best Fit

To ensure a column (or all the View columns) has enough width for its cells to entirely display their content, end-users can right-click a column header and choose the “Best Fit” (or “Best Fit (all columns)”) option.


Related API

Auto-Fill Column

A grid column assigned to the GridView.AutoFillColumn property automatically resizes to fill in any free space a View provides. In the animation below, the auto-fill column is “Address”.

Grid - Auto Fill Column

Fixed Columns

Modify a column’s GridColumn.Fixed to anchor it to a left or right View side. Fixed columns remain always visible while end-users scroll the View horizontally.

Data Grid - Fixed Columns Animation

The Fixed Columns demo illustrates how to supply grid columns with custom popup menus that allow users to anchor columns at runtime.

Related API

End-User Capabilities

By default, end-users can do the following:

Identify and Access Grid Columns in Code

To retrieve specific columns, utilize the following API:

See Also