-
Notifications
You must be signed in to change notification settings - Fork 1
/
TreeListInplaceEditViewController.cs
87 lines (85 loc) · 4.25 KB
/
TreeListInplaceEditViewController.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
83
84
85
86
87
using System;
using DevExpress.Xpo;
using DevExpress.ExpressApp;
using DevExpress.XtraTreeList;
using DevExpress.ExpressApp.DC;
using DevExpress.ExpressApp.Model;
using DevExpress.ExpressApp.Win.Core;
using DevExpress.XtraEditors.Repository;
using DevExpress.ExpressApp.Win.Controls;
using DevExpress.ExpressApp.TreeListEditors.Win;
namespace WinSolution.Module.Win {
public class TreeListInplaceEditViewController : ViewController<ListView> {
protected override void OnActivated() {
base.OnActivated();
TreeListEditor treeListEditor = View.Editor as TreeListEditor;
if (treeListEditor != null) {
treeListEditor.AllowEditChanged += treeListEditor_AllowEditChanged;
if (treeListEditor.TreeList != null) {
UpdateEditableTreeList(treeListEditor);
SubscribeToControlEvents(treeListEditor.TreeList);
}
treeListEditor.ControlsCreated += treeListEditor_ControlsCreated;
}
}
void treeListEditor_ControlsCreated(object sender, EventArgs e) {
TreeListEditor treeListEditor = (TreeListEditor)sender;
UpdateEditableTreeList(treeListEditor);
SubscribeToControlEvents(treeListEditor.TreeList);
}
private void SubscribeToControlEvents(TreeList treeList) {
treeList.CellValueChanged += treeList_CellValueChanged;
treeList.ShownEditor += treeList_ShownEditor;
}
protected override void OnDeactivated() {
TreeListEditor treeListEditor = View.Editor as TreeListEditor;
if (treeListEditor != null) {
treeListEditor.AllowEditChanged -= treeListEditor_AllowEditChanged;
treeListEditor.ControlsCreated -= treeListEditor_ControlsCreated;
ObjectTreeList treeList = (ObjectTreeList)treeListEditor.TreeList;
if (treeList != null) {
treeList.CellValueChanged -= treeList_CellValueChanged;
treeList.ShownEditor -= treeList_ShownEditor;
}
}
base.OnDeactivated();
}
private void UpdateEditableTreeList(TreeListEditor treeListEditor) {
ObjectTreeList treeList = treeListEditor.TreeList as ObjectTreeList;
if (treeList != null) {
treeList.OptionsBehavior.Editable = treeListEditor.AllowEdit;
foreach (RepositoryItem ri in treeList.RepositoryItems) {
ri.ReadOnly = !treeListEditor.AllowEdit;
}
foreach (TreeListColumnWrapper columnWrapper in treeListEditor.Columns) {
IModelColumn modelColumn = View.Model.Columns[columnWrapper.PropertyName];
if (modelColumn != null)
columnWrapper.Column.OptionsColumn.AllowEdit = modelColumn.AllowEdit;
}
treeList.OptionsBehavior.ImmediateEditor = true;
}
}
void treeListEditor_AllowEditChanged(object sender, EventArgs e) {
UpdateEditableTreeList((TreeListEditor)sender);
}
private void treeList_ShownEditor(object sender, EventArgs e) {
ObjectTreeList treeList = (ObjectTreeList)sender;
IGridInplaceEdit activeEditor = treeList.ActiveEditor as IGridInplaceEdit;
if (activeEditor != null && treeList.FocusedObject is IXPSimpleObject) {
activeEditor.GridEditingObject = treeList.FocusedObject;
}
}
private void treeList_CellValueChanged(object sender, CellValueChangedEventArgs e) {
ObjectTreeList treeList = (ObjectTreeList)sender;
object newValue = e.Value;
if (e.Value is IXPSimpleObject)
newValue = ObjectSpace.GetObject(e.Value);
object focusedObject = treeList.FocusedObject;
if (focusedObject != null) {
IMemberInfo focusedColumnMemberInfo = ObjectSpace.TypesInfo.FindTypeInfo(focusedObject.GetType()).FindMember(e.Column.FieldName);
if (focusedColumnMemberInfo != null)
focusedColumnMemberInfo.SetValue(focusedObject, Convert.ChangeType(newValue, focusedColumnMemberInfo.MemberType));
}
}
}
}