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.vb
166 lines (147 loc) · 5.26 KB
/
Form1.vb
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports DevExpress.XtraTreeList.Nodes
Imports DevExpress.XtraTreeList.Nodes.Operations
Namespace Q142554
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private Function CreateTable() As DataTable
Dim table As New DataTable()
Dim dataRow As DataRow
table.Columns.Add("ID", GetType(System.Int32))
table.Columns.Add("ID_2", GetType(System.Int32))
table.Columns.Add("Name", GetType(System.String))
table.Columns.Add("Priority", GetType(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
End Function
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
treeList1.DataSource = CreateTable()
End Sub
Private Sub OnTreeListBeforeCheckNode(ByVal sender As Object, ByVal e As DevExpress.XtraTreeList.CheckNodeEventArgs) Handles treeList1.BeforeCheckNode
e.State = (If(e.PrevState = CheckState.Checked, CheckState.Unchecked, CheckState.Checked))
End Sub
Private Sub OnTreeListAfterCheckNode(ByVal sender As Object, ByVal e As DevExpress.XtraTreeList.NodeEventArgs) Handles treeList1.AfterCheckNode
SetCheckedChildNodes(e.Node, e.Node.CheckState)
SetCheckedParentNodes(e.Node, e.Node.CheckState)
End Sub
Private Sub SetCheckedChildNodes(ByVal node As TreeListNode, ByVal check As CheckState)
For i As Integer = 0 To node.Nodes.Count - 1
node.Nodes(i).CheckState = check
SetCheckedChildNodes(node.Nodes(i), check)
Next i
End Sub
Private Sub SetCheckedParentNodes(ByVal node As TreeListNode, ByVal check As CheckState)
If node.ParentNode IsNot Nothing Then
Dim b As Boolean = False
Dim state As CheckState
For i As Integer = 0 To node.ParentNode.Nodes.Count - 1
state = CType(node.ParentNode.Nodes(i).CheckState, CheckState)
If Not check.Equals(state) Then
b = Not b
Exit For
End If
Next i
node.ParentNode.CheckState = If(b, CheckState.Indeterminate, check)
SetCheckedParentNodes(node.ParentNode, check)
End If
End Sub
Private Sub simpleButton1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles simpleButton1.Click
Dim operation As New CalcCheckedNodesOperation()
treeList1.NodesIterator.DoOperation(operation)
UpdateList(operation)
End Sub
Private Sub simpleButton2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles simpleButton2.Click
Dim operation As New CalcCheckedChildrenOperation(treeList1.FocusedNode)
treeList1.NodesIterator.DoOperation(operation)
UpdateList(operation)
End Sub
Private Sub UpdateList(ByVal operation As CalcCheckedNodesOperation)
listBoxControl1.Items.Clear()
listBoxControl1.Items.AddRange(operation.CheckedNodes.ToArray())
End Sub
End Class
Public Class CalcCheckedNodesOperation
Inherits TreeListOperation
'INSTANT VB NOTE: The field checkedNodes was renamed since Visual Basic does not allow fields to have the same name as other class members:
Private checkedNodes_Renamed As New List(Of String)()
Public ReadOnly Property CheckedNodes() As List(Of String)
Get
Return checkedNodes_Renamed
End Get
End Property
Public Overrides Sub Execute(ByVal node As TreeListNode)
If node.CheckState = CheckState.Checked Then
checkedNodes_Renamed.Add(CStr(node(node.TreeList.Columns(0))))
End If
End Sub
End Class
Public Class CalcCheckedChildrenOperation
Inherits CalcCheckedNodesOperation
Private parent As TreeListNode
Private isCalculationStart As Boolean = False
Public Sub New(ByVal parent As TreeListNode)
Me.parent = parent
End Sub
Public Overrides Sub Execute(ByVal node As TreeListNode)
If node.HasAsParent(parent) Then
MyBase.Execute(node)
End If
End Sub
Public Overrides Function CanContinueIteration(ByVal node As TreeListNode) As Boolean
If isCalculationStart AndAlso Not node.HasAsParent(parent) Then
Return False
End If
If node Is parent Then
isCalculationStart = True
End If
Return True
End Function
Public Overrides Function NeedsVisitChildren(ByVal node As TreeListNode) As Boolean
Return node Is parent OrElse node.HasAsParent(parent) OrElse parent.HasAsParent(node)
End Function
End Class
End Namespace