Skip to main content

ColumnView.Columns Property

Provides access to the collection of columns available for display within the View.

Namespace: DevExpress.XtraGrid.Views.Base

Assembly: DevExpress.XtraGrid.v24.2.dll

Declaration

[Browsable(false)]
[XtraSerializableProperty(XtraSerializationVisibility.Collection, true, true, true, 0, XtraSerializationFlags.DefaultValue)]
[XtraSerializablePropertyId(2)]
public virtual GridColumnCollection Columns { get; }

Property Value

Type Description
GridColumnCollection

A GridColumnCollection object representing a collection of available columns within the current View.

Remarks

Use the Columns property to access the collection of columns in the View. You can add, move, and delete columns. You can also access individual columns using indexer notation or by the bound field name.

using DevExpress.XtraGrid.Columns;

// Gets the first column in the Columns collection.
GridColumn colFirst = gridView1.Columns[0];
// Gets the column by its bound field name.
GridColumn colFirstName = gridView1.Columns["FirstName"];
// Adds a new column to the Columns collection.
gridView1.Columns.Add(new GridColumn() {
    Caption = "Last Name",
    FieldName = "LastName",
    Visible = true
});

In the CardView and LayoutView, columns are displayed as card fields. In the WinExplorerView, columns correspond to list item fields.

Column Types

View Type

Column Type

GridView

CardView

WinExplorerView

GridColumn

AdvBandedGridView

BandedGridView

BandedGridColumn

LayoutView

LayoutViewColumn

Read the following topic for detailed information and examples: Grid Columns.

Note

To display columns from the Columns collection in the WinExplorerView, assign them to the predefined WinExplorerView columns from ColumnSet.

Read the following topic for detailed information: WinExplorer View

Example

The following example demonstrates how to create a column within a View, and assign a specific editor to it.

    using DevExpress.XtraGrid.Views.BandedGrid;
    using DevExpress.XtraEditors.Repository;
    //...
    // Create a column
    BandedGridColumn col = advBandedGridView1.Columns.Add("Country") as BandedGridColumn;
    // Add a column to the first Band
    advBandedGridView1.Bands[0].Columns.Add(col);
    // Show the new column
    col.Visible = true;
    // Create a Repository Item
    RepositoryItemLookUpEdit columnEditor = new RepositoryItemLookUpEdit();
    // Customize the editor
    //...
    // Add the new Repository Item to the "RepositoryItems" collection
    gridControl1.RepositoryItems.Add(columnEditor);
    // Assign the editor to the new column
    col.ColumnEdit = columnEditor;

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.

See Also