Back to Devexpress

PersistentRepository Class

windowsforms-devexpress-dot-xtraeditors-dot-repository-ec3aa286.md

latest4.7 KB
Original Source

PersistentRepository Class

Stores repository items to be shared between container controls and components (GridControl, TreeList, RibbonControl, BarManager, etc).

Namespace : DevExpress.XtraEditors.Repository

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
public class PersistentRepository :
    EditorsRepositoryBase
vb
Public Class PersistentRepository
    Inherits EditorsRepositoryBase

The following members return PersistentRepository objects:

Remarks

The PersistentRepository class allows you to store repository items and reuse them across container controls.

Repository items added to a container control’s internal collection (for example, EditorContainer.RepositoryItems) cannot be reused. To use one repository item in multiple controls, do the following:

  1. Declare a PersistentRepository object.
  2. Create a repository item and add it to the PersistentRepository.Items collection.
  3. Assign the PersistentRepository object to a container control’s ExternalRepository property.
  4. Use the container control’s internal mechanisms to bind the repository item to a visual element.

Example

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

Inheritance

Object MarshalByRefObject Component DevExpress.XtraEditors.ComponentBase EditorsRepositoryBase PersistentRepository

See Also

PersistentRepository Members

ComponentEditorContainer.ExternalRepository

EditorContainer.ExternalRepository

DevExpress.XtraEditors.Repository Namespace