Description:
I've created my own editor derived from XtraEditors. What should I do to be able to add my editor to the grid's repository at design time?
Answer:
Applies to:
XtraGrid, XtraTreeList, XtraVerticalGrid, XtraBars
You should create a RepositoryItem class for your editor and declare a static (Shared in VB.NET) constructor and a Register method in it. The RepositoryItem class must be marked with the UserRepositoryItemAttribute attribute pointing to the Register method. It is also necessary to override the EditorTypeName property in both editor classes: RepositoryItem and BaseEdit descendants.
C#using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraEditors.Registrator;
namespace CustomEditors {
[UserRepositoryItem("Register")]
public class RepositoryItemMyButtonEdit : RepositoryItemButtonEdit {
static RepositoryItemMyButtonEdit() {
Register();
}
public RepositoryItemMyButtonEdit() {}
internal const string EditorName = "MyButtonEdit";
public static void Register() {
EditorRegistrationInfo.Default.Editors.Add(new EditorClassInfo(EditorName, typeof(MyButtonEdit),
typeof(RepositoryItemMyButtonEdit), typeof(DevExpress.XtraEditors.ViewInfo.ButtonEditViewInfo),
new DevExpress.XtraEditors.Drawing.ButtonEditPainter(), true, null, typeof(DevExpress.Accessibility.ButtonEditAccessible)));
}
public override string EditorTypeName {
get { return EditorName; }
}
}
public class MyButtonEdit : ButtonEdit {
static MyButtonEdit() {
RepositoryItemMyButtonEdit.Register();
}
public MyButtonEdit() {}
public override string EditorTypeName {
get { return RepositoryItemMyButtonEdit.EditorName; }
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public new RepositoryItemMyButtonEdit Properties {
get { return base.Properties as RepositoryItemMyButtonEdit; }
}
protected override void OnClickButton(DevExpress.XtraEditors.Drawing.EditorButtonObjectInfoArgs buttonInfo) {
ShowPopupForm();
base.OnClickButton(buttonInfo);
}
protected virtual void ShowPopupForm() {
using(Form form = new Form()) {
form.StartPosition = FormStartPosition.Manual;
form.Location = this.PointToScreen(new Point(0, Height));
form.ShowDialog();
}
}
}
}
Note: You should build the attached sample project prior to opening Form1 in design mode to avoid error messages about not found classes.
See Also:
Custom Editors
The Controls demo shipped with the XtraEditors
How to use a custom control in inplace mode in DevExpress containers
How to create a GridView descendant class and register it for design-time use
How to change a default in-place editor automatically created by the grid for specific column types
Can We Bind LookUpEdit to a particular GridControl Cell.
Hi,
I've created a new ticket (Q462247) on your behalf. Please refer to it for further correspondence.