wpf-devexpress-dot-xpf-dot-grid-dot-gridcontrol-94ec248c.md
Gets a collection of the GridControl‘s columns.
Namespace : DevExpress.Xpf.Grid
Assembly : DevExpress.Xpf.Grid.v25.2.dll
NuGet Package : DevExpress.Wpf.Grid.Core
public GridColumnCollection Columns { get; }
Public ReadOnly Property Columns As GridColumnCollection
| Type | Description |
|---|---|
| GridColumnCollection |
A collection of the GridControl‘s columns.
|
Tip
Topics :
The GridControl stores its columns in the Columns collection. This collection’s methods allow you to add new and remove existing columns. The GridColumn objects are individual columns. You can access columns by a field name (ColumnBase.FieldName) or an index.
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="Full Name"/>
<dxg:GridColumn FieldName="Birth Date"/>
</dxg:GridControl.Columns>
The Table View displays Columns collection’s items as columns. The Card View — as card fields.
Use the GridViewBase.VisibleColumns property to access only visible columns (the BaseColumn.Visible property value is true ).
The following code snippets (auto-collected from DevExpress Examples) contain references to the Columns property.
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.
wpf-data-grid-process-frequent-data-updates/CS/ChunkAndOptSummariesExample/MainWindow.xaml#L25
</dxg:GridControl.GroupSummary>
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="Name"/>
<dxg:GridControl ItemsSource="{Binding Source}" >
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="Date" Header="Date" UnboundType="DateTime" UnboundExpression="GetDate([DateTime])" AllowEditing="False"/>
wpf-datagrid-round-decimal-values/CS/FilterDuplicateRecords_Unbound/MainWindow.xaml#L16
<dxg:GridControl ItemsSource="{Binding Source}">
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="Name"/>
wpf-data-grid-display-group-summaries/CS/DisplayGroupSummaries_CodeBehind/MainWindow.xaml#L12
</dxg:GridControl.View>
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="UserName" />
wpf-data-grid-implement-custom-grouping/CS/CustomGrouping_CodeBehind/MainWindow.xaml#L12
CustomGroupDisplayText="OnCustomGroupDisplayText">
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="FirstName" />
if (grid.Columns[nameof(Invoice.Status)].GroupIndex == 0) {
var childRow = grid.FindRowByValue(grid.Columns[nameof(Invoice.Status)], InvoiceStatus.Invalidated);
var groupRow = grid.GetParentRowHandle(childRow);
wpf-grid-highlight-specific-cells/CS/MainWindow.xaml.cs#L13
ObservableCollection<HighlightedGridCell> cellsToHiglight = new ObservableCollection<HighlightedGridCell>();
cellsToHiglight.Add(new HighlightedGridCell(gridControl1.GetRow(0), gridControl1.Columns["ID"], Colors.Red));
CellsHighlightHelper.SetCellsToHighlight(gridControl1, cellsToHiglight);
wpf-data-grid-create-event-raised-on-layout-changes/CS/E4609/Implementation/GridLayoutHelper.cs#L22
base.OnAttached();
SubscribeColumns(Grid.Columns);
Grid.Columns.CollectionChanged += ColumnsCollectionChanged;
foreach(var rowHandle in rowHandles) {
foreach(var col in this._Grid.Columns) {
var cellText = this._Grid.GetCellDisplayText(rowHandle, col).ToLower();
wpf-data-grid-customize-automatically-generated-columns/CS/E2019/Window1.xaml.cs#L15
private void OnColumnsGenerated(object sender, RoutedEventArgs e) {
foreach (GridColumn column in grid.Columns) {
switch (column.FieldName) {
wpf-grid-highlight-specific-cells/VB/MainWindow.xaml.vb#L14
Dim cellsToHiglight As New ObservableCollection(Of HighlightedGridCell)()
cellsToHiglight.Add(New HighlightedGridCell(gridControl1.GetRow(0), gridControl1.Columns("ID"), Colors.Red))
CellsHighlightHelper.SetCellsToHighlight(gridControl1, cellsToHiglight)
wpf-data-grid-create-event-raised-on-layout-changes/VB/E4609/Implementation/GridLayoutHelper.vb#L24
MyBase.OnAttached()
SubscribeColumns(Grid.Columns)
AddHandler Grid.Columns.CollectionChanged, AddressOf ColumnsCollectionChanged
For Each rowHandle In rowHandles
For Each col In _Grid.Columns
Dim cellText = _Grid.GetCellDisplayText(rowHandle, col).ToLower()
wpf-grid-scrollbar-annotations/VB/WpfApplication25/MainWindow.xaml.vb#L45
view.SearchString = "Element2"
view.SelectCells(15, view.Grid.Columns(0), 25, view.Grid.Columns(1))
End Sub
See Also