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/

  • 相关阅读:
    创建发布Webservice以及wsimport工具
    Webservice介绍
    MongoDB简单认识
    Java集合的介绍
    Java虚拟机(JVM)体系结构概述及各种性能参数优化总结
    Java虚拟机(JVM)
    eclipse, idea安装lombok插件
    在window下, Java调用执行bat脚本
    python3对多线程处理
    Selenium常见元素定位方法和操作的学习介绍
  • 原文地址:https://www.cnblogs.com/Tonyyang/p/1764193.html
Copyright © 2011-2022 走看看