XAF 如何用下拉复选编辑枚举属性

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 (FlagsAttribute),  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 item) {
            
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();
            }
        }
    }
}

 

 

转载于:https://www.cnblogs.com/Tonyyang/archive/2010/08/18/1802195.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值