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.