Repositories and Repository Items
- 5 minutes to read
The editors of the DevExpress Editors Library can be used to perform in-place editing in the container controls provided by DevExpress. This topic describes the mechanism used to assign in-place editors to container controls.
Editor Repositories and Repository Items
Each editor which can be used for in-place editing has a Properties property which stores the settings and event handlers that correspond to this editor. This property represents an instance of the class derived from the RepositoryItem class. For instance, a date editor (DateEdit) provides the DateEdit.Properties property of the RepositoryItemDateEdit type.
Objects derived from the RepositoryItem class are called Repository Items. As you can see a repository item is a part of an editor (the repository item can be accessed via the editor's Properties property). But repository items can also exist as standalone objects.
You should create specific repository items as standalone objects to embed editors of particular types into container controls (XtraGrid, XtraVerticalGrid, Tree List and XtraBars). For instance, you need to create a RepositoryItemButtonEdit object to embed a ButtonEdit in a container control. See the Editors document for a list of the editors that can be used in-place and their corresponding repository items.
Enough information is contained in a repository item to create a fully functional editor. For instance, when an end-user clicks a cell within the Grid Control to activate an in-place editor, the grid does the following:
- First, it looks for the repository item which is assigned to this cell.
- It then creates an editor which corresponds to this repository item based upon the information provided by this item.
- Then all the settings and event handlers of the source repository item are copied to the editor's Properties property.
- Finally the editor is displayed within the clicked cell. When an end-user leaves the cell the editor is automatically destroyed but the source repository item isn't affected.
To use a repository item in a container control it must be added to this control's internal editor repository or to an external editor repository:
A control's internal repository.
Repository items added to this repository can only be used within this control and cannot be used within other container controls.
For EditorContainer descendants (XtraGrid, XtraTreeList, and XtraVerticalGrid) the internal editor repository can be accessed via the EditorContainer.RepositoryItems property. For ComponentEditorContainer descendants (XtraBars) use the ComponentEditorContainer.RepositoryItems property instead.
An external repository.
An external editor repository can be bound to multiple container controls within the same application. Repository items that are added to this repository can be shared between all the controls that are bound to it.
An external repository is represented by a PersistentRepository component. To bind an external repository to a container control, use the EditorContainer.ExternalRepository property. The ComponentEditorContainer.ExternalRepository property should be used for container components.
Containers can use repository items stored within both repositories. Thus, the entire collection of repository items that are available is comprised of the items stored within the internal repository and the items added to the bound external repository, if any.
Repository items created within containers at design time are automatically added to internal repositories. Items created via code should be added to repositories manually.
The following code shows how to assign a DateEdit in-place editor to a TreeList column in a TreeList control. This example creates the required repository item (RepositoryItemDateEdit), adds it to the control's internal repository and then binds the repository item to a column.
RepositoryItemDateEdit riDateEdit = new RepositoryItemDateEdit(); // Customize the item... // Add the item to the control's internal repository. treeList1.RepositoryItems.Add(riDateEdit); // Bind the item to the control's column. treeList1.Columns["Start Date"].ColumnEdit = riDateEdit;
All the container components and controls provided by DevExpress have their own facilities (which are all very similar) for managing their internal repository at design time. The following screenshots demonstrate how to add editors to a grid control's internal repository. This is done using the grid control's designer dialog.
The list displays all the repository items which reside within the grid's internal repository. To add an editor to the repository, press the down arrow near the Add button. This opens the dropdown list which allows you to specify the type of the repository item:
External repositories (PersistentRepository components) provide a similar designer for their collection of repository items. To invoke the designer, press the ellipsis button which corresponds to the EditorsRepositoryBase.Items property or utilize the component's smart tag.
Once repository items have been added to the desired collections and customized as required, you should bind them to particular visual elements (columns, data cells, etc). To learn how to do this, please refer to the documentation provided for the container control or component you are using.