Back to Devexpress

ColumnView.PopulateColumns() Method

windowsforms-devexpress-dot-xtragrid-dot-views-dot-base-dot-columnview-06425cfa.md

latest6.3 KB
Original Source

ColumnView.PopulateColumns() Method

Creates columns for all fields in the bound data source.

Namespace : DevExpress.XtraGrid.Views.Base

Assembly : DevExpress.XtraGrid.v25.2.dll

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

Declaration

csharp
public override void PopulateColumns()
vb
Public Overrides Sub PopulateColumns

Remarks

This method clears the column collection and creates new columns for fields in the View’s bound data source. The GridColumn.FieldName property of each column created is set to the respective bound field’s name. The GridColumn.VisibleIndex property is set with respect to the position of fields within the bound data source.

This overload of the PopulateColumns method is not in effect for detail pattern Views. 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, call PopulateColumns with a list parameter.

To create columns manually, use the methods provided by the ColumnView.Columns collection.

Note

A business object bound to a Grid Control may contain properties of collection types (e.g., of the List<> type). These properties instruct the Grid to enable master-detail mode (see Working with Master-Detail Relationships in Code). Columns corresponding to collection properties are not created in a master View.

The following code snippets (auto-collected from DevExpress Examples) contain references to the PopulateColumns() 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.

winforms-grid-edit-the-sqldatasource-connection-and-query-at-runtime/CS/T292798/Form1.cs#L30

csharp
gridView1.PopulateColumns();
}

winforms-dashboard-custom-items/CS/TutorialsCustomItems/CustomItems/SimpleTableItem.cs#L53

csharp
grid.DataSource = flatData;
view.PopulateColumns();
view.BestFitColumns();

winforms-dashboard-trend-line-indicators/CS/WinformsIndicator/Program.cs#L54

csharp
grid.DataSource = flatData;
view.PopulateColumns();
view.BestFitColumns();

winforms-grid-move-focused-row-up-down/CS/Form1.cs#L196

csharp
gridControl1.DataSource = dataTable1;
gridView1.PopulateColumns();
gridView1.Columns[OrderFieldName].SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;

winforms-grid-edit-the-sqldatasource-connection-and-query-at-runtime/VB/T292798/Form1.vb#L26

vb
sqlDataSource1.Fill()
    gridView1.PopulateColumns()
End Sub

winforms-dashboard-custom-items/VB/TutorialsCustomItems/CustomItems/SimpleTableItem.vb#L55

vb
grid.DataSource = flatData
view.PopulateColumns()
view.BestFitColumns()

winforms-dashboard-trend-line-indicators/VB/WinformsIndicator/Program.vb#L62

vb
grid.DataSource = flatData
view.PopulateColumns()
view.BestFitColumns()

winforms-grid-move-focused-row-up-down/VB/Form1.vb#L194

vb
gridControl1.DataSource = dataTable1
gridView1.PopulateColumns()
gridView1.Columns(OrderFieldName).SortOrder = DevExpress.Data.ColumnSortOrder.Ascending

See Also

Caption

Columns

DataSource

FieldName

AutoPopulateColumns

ColumnView Class

ColumnView Members

DevExpress.XtraGrid.Views.Base Namespace