zoukankan      html  css  js  c++  java
  • XAF中实现Combox属性编辑(官方)

    实现代码

    代码
    // Developer Express Code Central Example:
    // How to work with referenced properties via a single combo box  instead of the standard LookupPropertyEditor (Example)
    // 
    // See the KB article for more information.
    // 
    // You can find sample updates and versions for different programming languages here:
    // http://www.devexpress.com/example=E1101

    using System;
    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.Model;
    using DevExpress.ExpressApp.Editors;
    using DevExpress.ExpressApp.DC;
    using DevExpress.ExpressApp.Win.Editors;
    using DevExpress.Data.Filtering;
    using DevExpress.Xpo;
    using DevExpress.XtraEditors;
    using DevExpress.XtraEditors.Controls;

    namespace Dennis.DropDownEditorsModule.Win {
        [PropertyEditor(
    typeof(IXPSimpleObject))]
        
    public class MRULookupPropertyEditor : DXPropertyEditor, IComplexPropertyEditor {
            
    protected bool collectionLoadedCore = false;
            
    private string valueStringCore = string.Empty;
            
    private ObjectSpace objectSpaceCore = null;
            
    private XafApplication applicationCore = null;
            
    private MRUEdit controlCore = null;

            
    public MRULookupPropertyEditor(Type objectType, IModelMemberViewItem item) : base(objectType, item) { }
            
    public new MRUEdit Control {
                
    get {
                    
    return controlCore;
                }
            }
            
    protected ObjectSpace ObjectSpace {
                
    get { return objectSpaceCore; }
            }
            
    protected XafApplication Application {
                
    get { return applicationCore; }
            }
            
    protected IMemberInfo DefaultMember {
                
    get { return MemberInfo.MemberTypeInfo.DefaultMember; }
            }
            
    protected bool ShouldLoadCollection {
                
    get { return (!Object.ReferenceEquals(CurrentObject, null)) && (this.AllowEdit.ResultValue) && (!collectionLoadedCore); }
            }
            
    protected override object GetControlValueCore() {
                
    if (ShouldLoadCollection) {
                    
    foreach (IXPSimpleObject obj in objectSpaceCore.CreateCollection(MemberInfo.MemberTypeInfo.Type, nullnew SortingCollection(new SortProperty[] { new SortProperty("Name", DevExpress.Xpo.DB.SortingDirection.Ascending) }))) {
                        Control.Properties.Items.Add(DefaultMember.GetValue(obj));
                    }
                    collectionLoadedCore 
    = true;
                }
                
    return base.GetControlValueCore();
            }
            
    protected override object CreateControlCore() {
                controlCore 
    = new MRUEdit();
                controlCore.Properties.DropDownRows 
    = 10;
                controlCore.Validated 
    += new EventHandler(OnControlValidated);
                controlCore.EditValueChanged 
    += new EventHandler(OnControlEditValueChanged);
                controlCore.Properties.TextEditStyle 
    = this.AllowEdit.ResultValue ? TextEditStyles.Standard : TextEditStyles.DisableTextEditor;
                
    return controlCore;
            }
            
    private void OnControlValidated(object sender, EventArgs e) {
                WriteValueCore();
            }
            
    private void OnControlEditValueChanged(object sender, EventArgs e) {
                valueStringCore 
    = (Control.EditValue != null? Control.EditValue.ToString() : null;
            }
            
    protected override void WriteValueCore() {
                
    if (AllowEdit.ResultValue) {
                    Type objectType 
    = MemberInfo.MemberTypeInfo.Type;
                    IXPSimpleObject obj 
    = null;
                    
    if (!String.IsNullOrEmpty(valueStringCore)) {
                        obj 
    = objectSpaceCore.FindObject(objectType, new BinaryOperator(DefaultMember.Name, valueStringCore)) as IXPSimpleObject;
                        
    if (obj == null) {
                            obj 
    = objectSpaceCore.CreateObject(objectType) as IXPSimpleObject;
                            DefaultMember.SetValue(obj, valueStringCore);
                        }
                    }
                    PropertyValue 
    = obj;
                }
            }
            
    protected override void ReadValueCore() {
                
    if (PropertyValue != null) {
                    valueStringCore 
    = DefaultMember.GetValue(PropertyValue) as string;
                }
                Control.EditValue 
    = valueStringCore;
            }
            
    protected override void Dispose(bool disposing) {
                
    if (disposing && controlCore != null)
                {
                    controlCore.EditValueChanged 
    -= new EventHandler(OnControlEditValueChanged);
                }
                
    base.Dispose(disposing);
            }
            
    void IComplexPropertyEditor.Setup(ObjectSpace objectSpace, XafApplication application) {
                objectSpaceCore 
    = objectSpace;
                applicationCore 
    = application;
            }
        }
    }

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

  • 相关阅读:
    【BZOJ】1076: [SCOI2008]奖励关(状压dp+数学期望)
    【COGS & USACO】896. 圈奶牛(凸包)
    【wikioi】1553 互斥的数(hash+set)
    【wikioi】1229 数字游戏(dfs+水题)
    【COGS】714. USACO 1.3.2混合牛奶(贪心+水题)
    【wikioi】1403 新三国争霸(dp+kruskal)
    【wikioi】1108 方块游戏(模拟)
    [LeetCode] 270. Closest Binary Search Tree Value 最近的二叉搜索树的值
    [LeetCode] 261. Graph Valid Tree 图是否是树
    [LeetCode] 486. Predict the Winner 预测赢家
  • 原文地址:https://www.cnblogs.com/Tonyyang/p/1764193.html
Copyright © 2011-2022 走看看