https://documentation.devexpress.com/#WindowsForms/CustomDocument2434
添加列
TreeListColumn column = treeList1.Columns.Add(); column.Caption = @"建筑列表"; column.VisibleIndex = 0;
添加节点
treeList1.Nodes.Add(new object[] {item});
This method calls the TreeList.AppendNode(nodeData, ParentNode) method. The ParentNode property's value is passed as the method's second parameter. See the TreeList.AppendNode topic to learn more.
下面的代码,演示了添加多个列
private void Form1_Load(object sender, EventArgs e) { CreateColumns(treeList1); CreateNodes(treeList1); } private void CreateColumns(TreeList tl) { // Create three columns. tl.BeginUpdate(); tl.Columns.Add(); tl.Columns[0].Caption = "Customer"; tl.Columns[0].VisibleIndex = 0; tl.Columns.Add(); tl.Columns[1].Caption = "Location"; tl.Columns[1].VisibleIndex = 1; tl.Columns.Add(); tl.Columns[2].Caption = "Phone"; tl.Columns[2].VisibleIndex = 2; tl.EndUpdate(); } private void CreateNodes(TreeList tl) { tl.BeginUnboundLoad(); // Create a root node . TreeListNode parentForRootNodes = null; TreeListNode rootNode = tl.AppendNode( new object[] { "Alfreds Futterkiste", "Germany, Obere Str. 57", "030-0074321" }, parentForRootNodes); // Create a child of the rootNode tl.AppendNode(new object[] { "Suyama, Michael", "Obere Str. 55", "030-0074263" }, rootNode); // Creating more nodes // ... tl.EndUnboundLoad(); }
禁用编辑
禁用TreeList
treeList1.OptionsBehavior.Editable = false;
禁用单个列
TreeListColumn column = treeList1.Columns.Add(); column.Caption = @"建筑列表"; column.VisibleIndex = 0; column.OptionsColumn.AllowEdit = false; column.OptionsColumn.ReadOnly = true;
设置选中行的背景色
TreeList.Appearance.FocusedRow
https://www.devexpress.com/Support/Center/Question/Details/Q419028
To solve the issue, disable the TreeList.OptionsSelection.EnableAppearanceFocusedCell option.
标题
必须先添加列,才能有标题(标题是列标题,TreeList本身的Caption是不显示的)
添加节点图片
http://www.cnblogs.com/zzh1236/archive/2012/06/29/2570057.html
1.添加一个ImageCollection,控件名为imageCollection1 【多个form共用的话,可以使用SharedImageCollection】
按照节点的层级顺序添加图片
2. 设置TreeList的ColumnsImageList,SelectImageList,StateImageList为imageCollection1
3. 注册TreeList的CustomDrawNodeImages事件
treeList1.CustomDrawNodeImages += TreeList1_CustomDrawNodeImages; private void TreeList1_CustomDrawNodeImages(object sender, CustomDrawNodeImagesEventArgs e) { e.SelectImageIndex = e.Node.Level; }
NodeImage
概念:https://documentation.devexpress.com/#WindowsForms/CustomDocument1073
Nodes can display two images.
- Select Image - Typically indicates the node selection (focus) state. However, the same select image can be displayed for a node regardless of the node state. The TreeList provides a mechanism to automatically substitute替代 a select image when a node receives/loses focus.
- State Image - Typically indicates any state of a node.
If both select and state images are specified, the select image is displayed first.
The table below lists the main properties affecting element appearance.
控制节点的高度
Allows you to assign custom node height.
EventData
The event handler receives an argument of type CalcNodeHeightEventArgs containing data related to this event.
The following CalcNodeHeightEventArgs properties provide information specific to this event.
Node Gets the current Tree List node.
NodeHeight Gets or sets the current node's height in pixels.
Remarks
Write a CalcNodeHeight event handler to assign custom node height for the TreeList control.
The event fires for each visible node each time a node's look & feel is affected.
The parameter transmitted to the event allows you to identify a node whose height is calculated and assign the appropriate custom height.
Note: the CalcNodeHeight event fires only if the TreeListOptionsBehavior.AutoNodeHeight option is disabled.
Use the CalcNodeHeight event if you want to assign different node heights to the TreeList control.
If you want to assign the same height to all nodes, use the RowHeight property instead.