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 1
/
Form1.cs
99 lines (83 loc) · 3.35 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
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Nodes;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CustomTreeList_NodeHeight {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
List<MyRecord> list = new List<MyRecord>();
list.Add(new MyRecord(0, -1, "Corporate Headquarters", 1000000, "Monterey"));
list.Add(new MyRecord(1, 0, "Sales and Marketing", 22000, "San Francisco"));
list.Add(new MyRecord(2, 0, "Finance", 40000, "Monterey"));
list.Add(new MyRecord(3, 0, "Engineering", 1100000, "Monterey"));
list.Add(new MyRecord(4, -1, "Customer Services", 850000, "Burlington, VT"));
treeList1.DataSource = list;
treeList1.Columns["Budget"].Format.FormatType = DevExpress.Utils.FormatType.Numeric;
treeList1.Columns["Budget"].Format.FormatString = "c0";
}
private void Form1_Load(object sender, EventArgs e) {
treeList1.ForceInitialize();
treeList1.ExpandAll();
((MyTreeListNode)treeList1.Nodes[0]).Height = 35;
((MyTreeListNode)treeList1.Nodes[0].Nodes[1]).Height = 35;
}
}
public class MyTreeList : TreeList {
public MyTreeList() : base() {
OptionsBehavior.AutoNodeHeight = false;
}
protected override TreeListNode CreateNode(int nodeID, TreeListNodes owner, object tag) {
return new MyTreeListNode(nodeID, owner);
}
protected override void InternalNodeChanged(TreeListNode node, NodeChangeTypeEnum changeType) {
if (changeType == NodeChangeTypeEnum.User1)
LayoutChanged();
base.InternalNodeChanged(node, changeType);
}
protected override void RaiseCalcNodeHeight(TreeListNode node, ref int nodeHeight) {
MyTreeListNode myNode = node as MyTreeListNode;
if (myNode != null)
nodeHeight = myNode.Height;
else
base.RaiseCalcNodeHeight(node, ref nodeHeight);
}
public virtual int DefaultNodesHeight { get { return 18; } }
}
public class MyTreeListNode : TreeListNode {
const int minHeight = 5;
int height;
public MyTreeListNode(int id, TreeListNodes owner) : base(id, owner) {
this.height = (owner.TreeList as MyTreeList).DefaultNodesHeight;
}
public int Height {
get { return height; }
set {
if (Height == value || value < minHeight) return;
height = value;
Changed(NodeChangeTypeEnum.User1);
}
}
}
public class MyRecord {
public int ID { get; set; }
public int ParentID { get; set; }
public string Department { get; set; }
public string Location { get; set; }
public decimal Budget { get; set; }
public MyRecord(int id, int parentID, string department, decimal budget, string location) {
ID = id;
ParentID = parentID;
Department = department;
Budget = budget;
Location = location;
}
}
}