-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
65 lines (64 loc) · 2.24 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
using System;
using System.IO;
using System.Windows.Forms;
using DevExpress.XtraTreeList;
using System.Collections.Generic;
using DevExpress.XtraTreeList.Nodes;
using DevExpress.XtraEditors;
namespace Q351285 {
public partial class Form1 : XtraForm {
private string treeListDataFile = "data.xml";
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
InitData();
InitTreeList();
}
private void InitTreeList() {
treeList1.ForceInitialize();
UpdateNodesPositions(treeList1.Nodes);
treeList1.ExpandAll();
}
private void InitData() {
if(File.Exists(treeListDataFile)) {
dataTable1.ReadXml(treeListDataFile);
} else {
FillTable();
}
}
private void FillTable() {
dataTable1.Rows.Add(1, 0, "A", 0/*initially, this value is used to determine the node position*/);
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);
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e) {
SaveData();
}
private void SaveData() {
dataTable1.WriteXml(treeListDataFile);
}
private void UpdateNodesPositions(TreeListNodes nodes) {
var ns = new List<TreeListNode>();
foreach (TreeListNode n in nodes) {
ns.Add(n);
}
foreach (TreeListNode n in ns) {
UpdateNodesPositions(n.Nodes);
n.TreeList.SetNodeIndex(n, Convert.ToInt32(n.GetValue("Order")));
}
}
private void treeList1_AfterDragNode(object sender, AfterDragNodeEventArgs e) {
SaveNewRecordPosition(e);
}
private void SaveNewRecordPosition(NodeEventArgs e) {
var nodes = e.Node.ParentNode == null ? e.Node.TreeList.Nodes
: e.Node.ParentNode.Nodes;
for(var i = 0; i < nodes.Count; i++) {
nodes[i].SetValue(colSort, i);
}
}
}
}