XAF中实现Combox属性编辑(官方)
2010-06-24 10:03
435 查看
代码
// 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, null, new 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;
}
}
}
// 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, null, new 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;
}
}
}
相关文章推荐
- XAF中实现树形属性或树形编辑
- IOS Runtime属性关联实现表格编辑文本
- Java PropertyEditorSupport实现对象属性编辑
- 实现datagrid编辑功能需要设置DataKeyField属性的值
- XAF中如何实现Action创建一个可以编辑外连接对象的detail
- XAF 如何编辑当前选择的下拉列表项属性
- RobotTask:属性编辑对话框的实现
- QT中使用Qcombox和QCompleter实现可编辑的combox下拉提示,并设置样式
- XAF中如何实现Action创建一个可以编辑外连接对象的detail
- Mediar.Framework—业务的实现3 (控制UI控件的可视和可编辑属性、验证、以及一对一,一对多,多对多关系)
- EditText实现可选但不可编辑的属性(类似TextView)
- jquery实现flash翻屏并且可以在线编辑属性
- 实现PointF和SizeF的属性在PropertyGrid中可编辑的方法
- XAF 如何用下拉复选编辑枚举属性
- Silverlight表单控件实现自动属性编辑代码讲解
- 颜色控件【MFC】自己写一个ListCtrl控件(实现栅格属性表的编辑)-java教程
- mfc 可编辑combox不可用时,背景变黑,通过修改属性解决
- Android RoundedBitmapDrawable:Android官方的圆角图形图象实现方案
- lesson one:spring ioc,属性注入方式,实现自己的beanfactoy
- Android 属性动画 源码解析 深入了解其内部实现