-
Notifications
You must be signed in to change notification settings - Fork 6
/
LookUpEditEx.cs
82 lines (80 loc) · 3.13 KB
/
LookUpEditEx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.ComponentModel;
using DevExpress.ExpressApp.Win.Core;
using DevExpress.ExpressApp.Localization;
namespace Editors.Win {
[ToolboxItem(false)]
public class LookUpEditEx : DevExpress.XtraEditors.LookUpEdit, IGridInplaceEdit {
private object gridEditingObject;
static LookUpEditEx() { RepositoryItemLookUpEditEx.Register(); }
public LookUpEditEx() {
base.DataBindings.CollectionChanged += DataBindings_CollectionChanged;
}
protected override void Dispose(bool disposing) {
if(disposing) {
base.DataBindings.CollectionChanged -= DataBindings_CollectionChanged;
}
base.Dispose(disposing);
}
public override string EditorTypeName {
get { return RepositoryItemLookUpEditEx.EditorName; }
}
public new RepositoryItemLookUpEditEx Properties {
get { return (RepositoryItemLookUpEditEx)base.Properties; }
}
public override object EditValue {
get { return base.EditValue; }
set {
if(value != DBNull.Value && value != null) {
if(!Properties.Helper.LookupObjectType.IsInstanceOfType(value)) {
if(Properties.ThrowExceptionOnInvalidLookUpEditValueType) {
throw new InvalidCastException(SystemExceptionLocalizer.GetExceptionMessage(ExceptionId.UnableToCast,
value.GetType(),
Properties.Helper.LookupObjectType));
}
else {
base.EditValue = null;
return;
}
}
}
base.EditValue = value;
}
}
public object FindEditingObject() {
return BindingHelper.FindEditingObject(this);
}
private void OnEditingObjectChanged() {
InitializeDataSource();
if(FindEditingObject() == null && EditValue != null) {
EditValue = null;
}
}
public void InitializeDataSource() {
if(Properties != null && Properties.Helper != null) {
Properties.DataSource = Properties.Helper.CreateCollectionSource(FindEditingObject()).List;
}
}
private void DataBindings_CollectionChanged(object sender, CollectionChangeEventArgs e) {
OnEditingObjectChanged();
}
public new void UpdateDisplayText() {
base.UpdateDisplayText();
base.Refresh();
}
#region IGridInplaceEdit Members
System.Windows.Forms.ControlBindingsCollection IGridInplaceEdit.DataBindings {
get { return base.DataBindings; }
}
object IGridInplaceEdit.GridEditingObject {
get { return gridEditingObject; }
set {
if(gridEditingObject != value) {
gridEditingObject = value;
OnEditingObjectChanged();
}
}
}
#endregion
}
}