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/

  • 相关阅读:
    Vue 学习笔记之 —— 组件(踩了个坑)
    Vue 学习笔记之 —— 表单输入绑定
    js cookie
    python中线程、进程和协程的区别
    设计模式
    Mysql从入门到精通整理
    如何处理缓存失效、缓存穿透、缓存并发等问题
    mysql 查询当天、本周,本月,上一个月的数据
    Mysql分表和分区的区别、分库分表介绍与区别(转)
    mysql数据库死锁的产生原因及解决办法
  • 原文地址:https://www.cnblogs.com/Tonyyang/p/1764193.html
Copyright © 2011-2022 走看看