Skip to main content

ColumnView.PopulateColumns(DataTable) Method

Creates columns for all the fields of the specified DataTable.

Namespace: DevExpress.XtraGrid.Views.Base

Assembly: DevExpress.XtraGrid.v23.2.dll

NuGet Packages: DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

public void PopulateColumns(
    DataTable dataTable
)

Parameters

Name Type Description
dataTable DataTable

A DataTable object representing a data table whose fields will provide data for the created columns.

Remarks

This method clears the column collection and creates columns for visible fields within the specified data table. The GridColumn.FieldName property of each column is set to the respective bound field’s name. The GridColumn.VisibleIndex property is set to the bound field’s position within the data table.

Unlike the PopulateColumns method, which has no parameters, the current overload does not create grid columns for the System.Data.DataColumn objects that have the ColumnMapping property set to MappingType.Hidden. So, you can set this property for specific DataColumn objects to MappingType.Hidden to prevent them from being added to the grid control.

The PopulateColumns method, which has no parameters, cannot be used to create columns for detail pattern Views. If you need to populate pattern Views with columns, you need to use the method overloads that take appropriate parameters. If the pattern View is bound to a DataTable, then use the PopulateColumns method that takes a DataTable parameter. Similarly, if the pattern View is bound to a list (IXtraList or ITypedList), call PopulateColumns with a list parameter.

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the PopulateColumns(DataTable) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also