Back to Devexpress

How to: Create a Column and Assign an Editor to It

windowsforms-3062-controls-and-libraries-data-grid-examples-data-presentation-how-to-create-a-column-and-assign-an-editor-to-it.md

latest1.8 KB
Original Source

How to: Create a Column and Assign an Editor to It

  • Sep 10, 2019

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

csharp
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;
vb
Imports DevExpress.XtraGrid.Views.BandedGrid
    Imports DevExpress.XtraEditors.Repository
    '...
    ' Create a column
    Dim col As BandedGridColumn = TryCast(advBandedGridView1.Columns.Add("Country"), 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
    Dim columnEditor As 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

See the Cell Values, Editors, and Validation topic for more information about column editors.