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.v24.2.dll
Declaration
Related API Members
The following members return PersistentRepository objects:
Remarks
The PersistentRepository class represents a component which allows you to store and manipulate repository items. This is used to supply inplace editors for container controls. Repository item objects are capable of creating editor objects based on their settings. Thus, providing a repository item is enough for a control to create inplace editors.
The PersistentRepository component is designed to share and reuse repository items between several container controls/components. To share a repository item between several container controls, you need to:
- create a repository item and add it to a PersistentRepository component’s PersistentRepository.Items collection;
- link the PersistentRepository to specific container controls using their ExternalRepository properties. For controls derived from EditorContainer, use the EditorContainer.ExternalRepository property. For ComponentEditorContainer descendants, use the ComponentEditorContainer.ExternalRepository property.
After the steps outlined above have been performed, you can use the container control’s internal mechanisms to bind a repository item to a particular visual element.
Container controls also maintain internal repositories. Repository items from this collection cannot be shared between multiple container controls. To access a control’s internal repository use the EditorContainer.RepositoryItems and ComponentEditorContainer.RepositoryItems properties.
Note: You can create a repository item as a standalone object, i.e. without adding it to the internal repository item collection or to ExternalRepository. In order to specify the repository item as an inplace editor for a container control, however, you must add the item either to the persistent repository specified by the control’s ExternalRepository property or to the control’s internal repository. This ensures that changes made to the repository item object are automatically applied to all inplace editors to which the repository item is assigned.
Example
The following example shows how to share a single repository item between two Grid Controls. For this purpose, an external PersistentRepository
component must be used.
First, add a specific repository item to the persistent repository and customize it depending upon your needs. Then link the persistent repository to the ExternalRepository properties of the required grid controls. After that, assign the repository item to the required grid columns via the ColumnEdit property.
In this example we create a repository item corresponding to an ImageComboBoxEdit editor.
using DevExpress.XtraEditors.Repository;
//Add a repository item corresponding to a combo box editor to the persistent repository
RepositoryItemComboBox riCombo = new RepositoryItemComboBox();
riCombo.Items.AddRange(new string[] {"Cash", "Visa", "Master", "Am.Express" });
persistentRepository1.Items.Add(riCombo);
//Link the persistent repository to two grid controls
gridControl1.ExternalRepository = persistentRepository1;
gridControl2.ExternalRepository = persistentRepository1;
//Now you can define the repository item as an inplace editor of columns for the two grids
(gridControl1.MainView as GridView).Columns["PaymentType"].ColumnEdit = riCombo;
(gridControl2.MainView as GridView).Columns["PaymentType"].ColumnEdit = riCombo;