zoukankan      html  css  js  c++  java
  • 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();
                }
            }
        }
    }

    欢迎转载,转载请注明出处:http://www.cnblogs.com/Tonyyang/

  • 相关阅读:
    Element没更新了?Element没更新,基于El的扩展库更新
    MVC与Validate验证提示的样式修改
    封装两个简单的Jquery组件
    VS20XX-Add-In插件开发
    CentOS7 配置环境
    PHP Laravel 5.4 环境搭建
    【设计经验】5、Verilog对数据进行四舍五入(round)与饱和(saturation)截位
    【设计经验】4、SERDES关键技术总结
    【高速接口-RapidIO】6、Xilinx RapidIO核仿真与包时序分析
    【高速接口-RapidIO】5、Xilinx RapidIO核例子工程源码分析
  • 原文地址:https://www.cnblogs.com/Tonyyang/p/1802195.html
Copyright © 2011-2022 走看看