Back to Devexpress

How to: Share Editors Between Multiple XtraGrid Controls

windowsforms-9511-controls-and-libraries-editors-and-simple-controls-examples-how-to-share-editors-between-multiple-xtragrid-controls.md

latest1.8 KB
Original Source

How to: Share Editors Between Multiple XtraGrid Controls

  • Oct 25, 2019

The following example uses a PersistentRepository to reuse a single repository item in a Data Grid and a Tree List.

csharp
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;

public partial class Form1 : XtraForm {
    public Form1() {
        InitializeComponent();
        // Create a persistent repository
        PersistentRepository rep = new PersistentRepository();

        //Add a repository item to the persistent repository
        RepositoryItemSpinEdit spin = new RepositoryItemSpinEdit();
        rep.Items.Add(spin);

        //Link the persistent repository to controls
        gridControl1.ExternalRepository = rep;
        treeList1.ExternalRepository = rep;

        // Assign the repository item to columns
        gridView1.Columns["Id"].ColumnEdit = spin;
        treeList1.Columns["Id"].ColumnEdit = spin;
    }
}
vb
Imports DevExpress.XtraEditors
Imports DevExpress.XtraEditors.Repository

Public Partial Class Form1
    Inherits XtraForm

    Public Sub New()
        InitializeComponent()
        ' Create a persistent repository
        Dim rep As New PersistentRepository()

        ' Add a repository item to the persistent repository
        Dim spin As New RepositoryItemSpinEdit()
        rep.Items.Add(spin)

        ' Link the persistent repository to controls
        gridControl1.ExternalRepository = rep
        treeList1.ExternalRepository = rep

        ' Assign the repository item to columns
        gridView1.Columns("Id").ColumnEdit = spin
        treeList1.Columns("Id").ColumnEdit = spin
    End Sub
End Class