This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
/
MyTreeList.cs
124 lines (102 loc) · 4.42 KB
/
MyTreeList.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using DevExpress.Utils.Serializing;
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Columns;
using DevExpress.XtraTreeList.ViewInfo;
using System.ComponentModel;
namespace TreeListCellMerging
{
public delegate void AllowMergeColumnCellsEventHandler(object sender, AllowMergeColumnCellsEventArgs e);
public delegate void AllowMergeRowCellsEventHandler(object sender, AllowMergeRowCellsEventArgs e);
public class MyTreeList : TreeList
{
public TreeListColumn _OldColumn;
public TreeListColumnCollection MergedColumns;
public MyTreeList()
: base()
{
this.FocusedColumnChanged += MyTreeList_FocusedColumnChanged;
this.FocusedNodeChanged += MyTreeList_FocusedNodeChanged;
}
public event AllowMergeRowCellsEventHandler AllowMergeRowCells;
private void JumpIfInMergedCell(FocusedColumnChangedEventArgs e, int step)
{
TreeListColumn nextColumn = GetColumnByVisibleIndex(e.Column.VisibleIndex - 1);
if(Equals(this.FocusedNode.GetValue(e.Column), this.FocusedNode.GetValue(nextColumn)))
{
this.FocusedColumn = this.GetColumnByVisibleIndex(FocusedColumn.VisibleIndex + step);
}
}
private void MovementUpDownInMergeColumn(FocusedNodeChangedEventArgs e)
{
if(e.OldNode != null && (this.FocusedColumn.VisibleIndex - 1) > 0)
{
if(Equals(e.Node.GetValue(this.GetColumnByVisibleIndex(this.FocusedColumn.VisibleIndex)),
e.Node.GetValue(this.GetColumnByVisibleIndex(this.FocusedColumn.VisibleIndex - 1))))
this.FocusedColumn = this.GetColumnByVisibleIndex(FocusedColumn.VisibleIndex - 1);
}
}
void MyTreeList_FocusedColumnChanged(object sender, FocusedColumnChangedEventArgs e)
{
if(e.OldColumn == null || e.Column == null) return;
ReturnIfBeyondRightBorder(e);
if(e.OldColumn.VisibleIndex < e.Column.VisibleIndex && this.Columns[e.Column.VisibleIndex + 1] != null)
JumpIfInMergedCell(e, 1);
if(e.OldColumn.VisibleIndex > e.Column.VisibleIndex && this.Columns[e.Column.VisibleIndex - 1] != null)
JumpIfInMergedCell(e, -1);
}
void MyTreeList_FocusedNodeChanged(object sender, FocusedNodeChangedEventArgs e)
{
MovementUpDownInMergeColumn(e);
}
private void ReturnIfBeyondRightBorder(FocusedColumnChangedEventArgs e)
{
if(this.FocusedNode.GetValue(e.Column).ToString() == this.FocusedNode.GetValue(e.OldColumn).ToString()
&& this.Columns[e.Column.VisibleIndex + 1] == null)
{ this.FocusedColumn = e.OldColumn; }
}
protected override TreeListOptionsView CreateOptionsView()
{
return new MyTreeListOptionsView(this);
}
protected override TreeListViewInfo CreateViewInfo()
{
return new MyTreeListViewInfo(this);
}
protected internal void RaiseMergeRowCells(AllowMergeRowCellsEventArgs args)
{
if(AllowMergeRowCells != null)
AllowMergeRowCells(this, args);
}
public override void ShowEditor()
{
RowInfo ri = this.FocusedRow;
CellInfo cell = ri[this.FocusedColumn];
if(cell == null)
{
if(this.FocusedColumn.VisibleIndex == 0)
return;
this.FocusedColumn = this.VisibleColumns[this.FocusedColumn.VisibleIndex - 1];
base.ShowEditor();
return;
}
base.ShowEditor();
}
public override bool CanShowEditor {
get {
return base.CanShowEditor;
}
}
[Description("Provides access to the tree list's display options."), Category("Options"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
XtraSerializableProperty(XtraSerializationVisibility.Content, XtraSerializationFlags.DefaultValue)]
public new MyTreeListOptionsView OptionsView {
get {
return base.OptionsView as MyTreeListOptionsView;
}
}
public new MyTreeListViewInfo ViewInfo {
get {
return (MyTreeListViewInfo)base.ViewInfo;
}
}
}
}