DevExpress and GridControl: how to add custom columns and override RepositoryItem

Source: Internet
Author: User

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 ();
//}
//}
}
}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.