DevExpress and GridControl: how to add custom columns and override RepositoryItem
How to add custom controls to XtraGrid
How to add a self-created XtraEditors editing control to XtraGrid
You can create a RepositoryItem derived class and declare the static constructor and Registration Method for it. To use it in the designer, you must add the UserRepositoryItemAttribute attribute tag to the registration method, you must also override the EditorTypeName attribute of the RepositoryItem and BaseEdit Derived classes.
This method is applicable to XtraGrid, XtraTreeList, XtraVerticalGrid, and XtraBars.
Note: Add reference: DevExpress. XtraEditors. v10.2
[C # example]
[Csharp]
Using DevExpress. XtraEditors;
Using DevExpress. XtraEditors. Repository;
Using DevExpress. XtraEditors. Registrator;
Using System. Windows. Forms;
Using System. Drawing;
Using System. ComponentModel;
Namespace CustomEditors
{
[UserRepositoryItem ("Register")]
Public class RepositoryItemMyEdit: RepositoryItemTextEdit
{
Static RepositoryItemMyEdit ()
{
Register ();
}
Public RepositoryItemMyEdit (){}
Internal const string EditorName = "MyEdit ";
Public static void Register ()
{
EditorRegistrationInfo. Default. Editors. Add (new EditorClassInfo (EditorName, typeof (MyEdit ),
Typeof (RepositoryItemMyEdit), typeof (DevExpress. XtraEditors. ViewInfo. TextEditViewInfo ),
New DevExpress. XtraEditors. Drawing. TextEditPainter (), true, null, typeof (DevExpress. Accessibility. TextEditAccessible )));
}
Public override string EditorTypeName
{
Get {return EditorName ;}
}
}
Public class MyEdit: TextEdit
{
Static MyEdit ()
{
RepositoryItemMyEdit. Register ();
}
Public MyEdit (){}
Public string DisplayText {set; get ;}
Public override string EditorTypeName
{
Get {return RepositoryItemMyEdit. EditorName ;}
}
[DesignerSerializationVisibility (DesignerSerializationVisibility. Content)]
Public new RepositoryItemMyEdit Properties
{
Get {return base. Properties as RepositoryItemMyEdit ;}
}
// 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 ();
//}
//}
}
}
Using DevExpress. XtraEditors;
Using DevExpress. XtraEditors. Repository;
Using DevExpress. XtraEditors. Registrator;
Using System. Windows. Forms;
Using System. Drawing;
Using System. ComponentModel;
Namespace CustomEditors
{
[UserRepositoryItem ("Register")]
Public class RepositoryItemMyEdit: RepositoryItemTextEdit
{
Static RepositoryItemMyEdit ()
{
Register ();
}
Public RepositoryItemMyEdit (){}
Internal const string EditorName = "MyEdit ";
Public static void Register ()
{
EditorRegistrationInfo. Default. Editors. Add (new EditorClassInfo (EditorName, typeof (MyEdit ),
Typeof (RepositoryItemMyEdit), typeof (DevExpress. XtraEditors. ViewInfo. TextEditViewInfo ),
New DevExpress. XtraEditors. Drawing. TextEditPainter (), true, null, typeof (DevExpress. Accessibility. TextEditAccessible )));
}
Public override string EditorTypeName
{
Get {return EditorName ;}
}
}
Public class MyEdit: TextEdit
{
Static MyEdit ()
{
RepositoryItemMyEdit. Register ();
}
Public MyEdit (){}
Public string DisplayText {set; get ;}
Public override string EditorTypeName
{
Get {return RepositoryItemMyEdit. EditorName ;}
}
[DesignerSerializationVisibility (DesignerSerializationVisibility. Content)]
Public new RepositoryItemMyEdit Properties
{
Get {return base. Properties as RepositoryItemMyEdit ;}
}
// 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 ();
//}
//}
}
}