How does xaf use the drop-down check box to edit enumeration attributes?

Source: Internet
Author: User

Http://www.devexpress.com/Support/Center/e/E689.aspx

 

 
Using system;
Using system. Windows. forms;
Using devexpress. xtraeditors;
Using devexpress. expressapp. utils;
Using devexpress. expressapp. model;
Using devexpress. expressapp. editors;
Using devexpress. xtraeditors. repository;

Namespace winsolution. Module. Win {
[Propertyeditor (typeof (system. Enum), true)]
Public class enumpropertyeditorex: devexpress. expressapp. Win. Editors. enumpropertyeditor {
Public enumpropertyeditorex (type objecttype, imodelmemberviewitem Model)
: Base (objecttype, model ){
}
Private bool typehasflagsattribute (){
Return getunderlyingtype (). getcustomattributes (typeof (flagsattrites), true). length> 0;
}
Protected override object createcontrolcore (){
Checkedcomboboxedit checkededit = new checkedcomboboxedit ();
Checkededit. textchanged + = checkededit_textchanged;
If (typehasflagsattribute ())
Return checkededit;
Return base. createcontrolcore ();
}
// Dennis: This code is needed to bypass a binding problem in the xtraeditors (s35490)
Private void checkededit_textchanged (Object sender, eventargs e ){
(Checkedcomboboxedit) sender). refresheditvalue ();
}
Protected override repositoryitem createrepositoryitem (){
If (typehasflagsattribute ())
Return new repositoryitemcheckedcomboboxedit ();
Return base. createrepositoryitem ();
}
Protected override void setuprepositoryitem (repositoryitem ){
Base. setuprepositoryitem (item );
If (typehasflagsattribute ()){
Enumdescriptor descriptor = new enumdescriptor (getunderlyingtype ());
Repositoryitemcheckedcomboboxedit checkeditem = (repositoryitemcheckedcomboboxedit) item );
Checkeditem. beginupdate ();
Checkeditem. Items. Clear ();
Checkeditem. selectallitemvisible = false;
// DENNIS: This is required to show localized items in the editor.
Foreach (object Value in descriptor. values)
Checkeditem. Items. Add (value, descriptor. getcaption (value), checkstate. Unchecked, true );
// DENNIS: use this method if you don't to show localized items in the editor.
// Checkeditem. setflags (getunderlyingtype ());
Checkeditem. endupdate ();
}
}
}
}

 

 

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.