This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
147 lines (131 loc) · 5.53 KB
/
Form1.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraTreeList.Nodes;
using DevExpress.XtraTreeList.Nodes.Operations;
namespace Q142554 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
DataTable CreateTable()
{
DataTable table = new DataTable();
DataRow dataRow;
table.Columns.Add("ID", typeof(System.Int32));
table.Columns.Add("ID_2", typeof(System.Int32));
table.Columns.Add("Name", typeof(System.String));
table.Columns.Add("Priority", typeof(System.String));
dataRow = table.NewRow();
dataRow["ID"] = 1;
dataRow["ID_2"] = 0;
dataRow["Name"] = "Project A";
dataRow["Priority"] = "High";
table.Rows.Add(dataRow);
dataRow = table.NewRow();
dataRow["ID"] = 2;
dataRow["ID_2"] = 1;
dataRow["Name"] = "Deliverable 1";
dataRow["Priority"] = "Normal";
table.Rows.Add(dataRow);
dataRow = table.NewRow();
dataRow["ID"] = 3;
dataRow["ID_2"] = 2;
dataRow["Name"] = "This task is mine A";
dataRow["Priority"] = "High";
table.Rows.Add(dataRow);
dataRow = table.NewRow();
dataRow["ID"] = 4;
dataRow["ID_2"] = 2;
dataRow["Name"] = "This task isn't mine";
dataRow["Priority"] = "Low";
table.Rows.Add(dataRow);
dataRow = table.NewRow();
dataRow["ID"] = 5;
dataRow["ID_2"] = 0;
dataRow["Name"] = "Project B";
dataRow["Priority"] = "Normal";
table.Rows.Add(dataRow);
dataRow = table.NewRow();
dataRow["ID"] = 6;
dataRow["ID_2"] = 5;
dataRow["Name"] = "This task is mine B";
dataRow["Priority"] = "High";
table.Rows.Add(dataRow);
return table;
}
private void Form1_Load(object sender, EventArgs e) {
treeList1.DataSource = CreateTable();
}
private void OnTreeListBeforeCheckNode(object sender, DevExpress.XtraTreeList.CheckNodeEventArgs e) {
e.State = (e.PrevState == CheckState.Checked ? CheckState.Unchecked : CheckState.Checked);
}
private void OnTreeListAfterCheckNode(object sender, DevExpress.XtraTreeList.NodeEventArgs e) {
SetCheckedChildNodes(e.Node, e.Node.CheckState);
SetCheckedParentNodes(e.Node, e.Node.CheckState);
}
private void SetCheckedChildNodes(TreeListNode node, CheckState check) {
for (int i = 0; i < node.Nodes.Count; i++) {
node.Nodes[i].CheckState = check;
SetCheckedChildNodes(node.Nodes[i], check);
}
}
private void SetCheckedParentNodes(TreeListNode node, CheckState check) {
if (node.ParentNode != null) {
bool b = false;
CheckState state;
for (int i = 0; i < node.ParentNode.Nodes.Count; i++) {
state = (CheckState)node.ParentNode.Nodes[i].CheckState;
if (!check.Equals(state)) {
b = !b;
break;
}
}
node.ParentNode.CheckState = b ? CheckState.Indeterminate : check;
SetCheckedParentNodes(node.ParentNode, check);
}
}
private void simpleButton1_Click(object sender, EventArgs e) {
CalcCheckedNodesOperation operation = new CalcCheckedNodesOperation();
treeList1.NodesIterator.DoOperation(operation);
UpdateList(operation);
}
private void simpleButton2_Click(object sender, EventArgs e) {
CalcCheckedChildrenOperation operation = new CalcCheckedChildrenOperation(treeList1.FocusedNode);
treeList1.NodesIterator.DoOperation(operation);
UpdateList(operation);
}
private void UpdateList(CalcCheckedNodesOperation operation) {
listBoxControl1.Items.Clear();
listBoxControl1.Items.AddRange(operation.CheckedNodes.ToArray());
}
}
public class CalcCheckedNodesOperation :TreeListOperation {
private List<string> checkedNodes = new List<string>();
public List<string> CheckedNodes { get { return checkedNodes; } }
public override void Execute(TreeListNode node) {
if (node.CheckState == CheckState.Checked)
checkedNodes.Add((string)node[node.TreeList.Columns[0]]);
}
}
public class CalcCheckedChildrenOperation : CalcCheckedNodesOperation {
private TreeListNode parent;
private bool isCalculationStart = false;
public CalcCheckedChildrenOperation(TreeListNode parent) { this.parent = parent; }
public override void Execute(TreeListNode node) {
if (node.HasAsParent(parent)) base.Execute(node);
}
public override bool CanContinueIteration(TreeListNode node) {
if (isCalculationStart && !node.HasAsParent(parent)) return false;
if (node == parent) isCalculationStart = true;
return true;
}
public override bool NeedsVisitChildren(TreeListNode node) {
return node == parent || node.HasAsParent(parent) || parent.HasAsParent(node);
}
}
}