Back to Devexpress

GridControl.Columns Property

wpf-devexpress-dot-xpf-dot-grid-dot-gridcontrol-94ec248c.md

latest9.6 KB
Original Source

GridControl.Columns Property

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

Declaration

csharp
public GridColumnCollection Columns { get; }
vb
Public ReadOnly Property Columns As GridColumnCollection

Property Value

TypeDescription
GridColumnCollection

A collection of the GridControl‘s columns.

|

Remarks

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.

xaml
<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

xml
</dxg:GridControl.GroupSummary>
<dxg:GridControl.Columns>
    <dxg:GridColumn FieldName="Name"/>

wpf-data-grid-display-datetime-value-in-separate-date-and-time-columns/CS/DateAndTimeColumns_Unbound/MainWindow.xaml#L16

xml
<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

xml
<dxg:GridControl ItemsSource="{Binding Source}">
    <dxg:GridControl.Columns>
        <dxg:GridColumn FieldName="Name"/>

wpf-data-grid-display-group-summaries/CS/DisplayGroupSummaries_CodeBehind/MainWindow.xaml#L12

xml
</dxg:GridControl.View>
<dxg:GridControl.Columns>
    <dxg:GridColumn FieldName="UserName" />

wpf-data-grid-implement-custom-grouping/CS/CustomGrouping_CodeBehind/MainWindow.xaml#L12

xml
CustomGroupDisplayText="OnCustomGroupDisplayText">
<dxg:GridControl.Columns>
    <dxg:GridColumn FieldName="FirstName" />

wpf-grid-prevent-expand-collapse-operations-for-group-rows/CS/Forbid_Expand_Collapse/MainWindow.xaml.cs#L14

csharp
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

csharp
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

csharp
base.OnAttached();
SubscribeColumns(Grid.Columns);
Grid.Columns.CollectionChanged += ColumnsCollectionChanged;

how-to-create-search-window-with-find-previous-and-find-next-buttons-in-gridcontrol-t127527/CS/DevExpress.Example01/SearchBehavior/SearchWindow.xaml.cs#L209

csharp
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

csharp
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

vb
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

vb
MyBase.OnAttached()
SubscribeColumns(Grid.Columns)
AddHandler Grid.Columns.CollectionChanged, AddressOf ColumnsCollectionChanged

how-to-create-search-window-with-find-previous-and-find-next-buttons-in-gridcontrol-t127527/VB/DevExpress.Example01/SearchBehavior/SearchWindow.xaml.vb#L200

vb
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

vb
view.SearchString = "Element2"
    view.SelectCells(15, view.Grid.Columns(0), 25, view.Grid.Columns(1))
End Sub

See Also

VisibleColumns

Columns and Card Fields

GridControl Class

GridControl Members

DevExpress.Xpf.Grid Namespace