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/

  • 相关阅读:
    grep之字符串搜索算法Boyer-Moore由浅入深(比KMP快3-5倍)
    php中htmlspecialchars,htmlentities用法
    php get_magic_quotes_gpc()函数用法介绍
    .animate()
    想用PHP做抽奖系统,思路..
    “评论盖楼”的设计思路
    JavaScript有关的10个怪癖和秘密
    Android上常见度量单位【xdpi、hdpi、mdpi、ldpi】解读
    项目描述 Project Description
    instance initializer
  • 原文地址:https://www.cnblogs.com/Tonyyang/p/1802195.html
Copyright © 2011-2022 走看看