-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.vb
78 lines (64 loc) · 2.3 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
Imports System
Imports System.IO
Imports System.Windows.Forms
Imports DevExpress.XtraTreeList
Imports System.Collections.Generic
Imports DevExpress.XtraTreeList.Nodes
Imports DevExpress.XtraEditors
Namespace Q351285
Public Partial Class Form1
Inherits XtraForm
Private treeListDataFile As String = "data.xml"
Public Sub New()
InitializeComponent()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
InitData()
InitTreeList()
End Sub
Private Sub InitTreeList()
treeList1.ForceInitialize()
UpdateNodesPositions(treeList1.Nodes)
treeList1.ExpandAll()
End Sub
Private Sub InitData()
If File.Exists(treeListDataFile) Then
dataTable1.ReadXml(treeListDataFile)
Else
FillTable()
End If
End Sub
Private Sub FillTable()
dataTable1.Rows.Add(1, 0, "A", 0)
dataTable1.Rows.Add(2, 1, "B", 1)
dataTable1.Rows.Add(3, 1, "C", 2)
dataTable1.Rows.Add(4, 0, "D", 3)
dataTable1.Rows.Add(5, 4, "E", 4)
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs)
SaveData()
End Sub
Private Sub SaveData()
dataTable1.WriteXml(treeListDataFile)
End Sub
Private Sub UpdateNodesPositions(ByVal nodes As TreeListNodes)
Dim ns = New List(Of TreeListNode)()
For Each n As TreeListNode In nodes
ns.Add(n)
Next
For Each n As TreeListNode In ns
UpdateNodesPositions(n.Nodes)
n.TreeList.SetNodeIndex(n, Convert.ToInt32(n.GetValue("Order")))
Next
End Sub
Private Sub treeList1_AfterDragNode(ByVal sender As Object, ByVal e As AfterDragNodeEventArgs)
SaveNewRecordPosition(e)
End Sub
Private Sub SaveNewRecordPosition(ByVal e As NodeEventArgs)
Dim nodes = If(e.Node.ParentNode Is Nothing, e.Node.TreeList.Nodes, e.Node.ParentNode.Nodes)
For i = 0 To nodes.Count - 1
nodes(i).SetValue(colSort, i)
Next
End Sub
End Class
End Namespace