添加列
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 property's value is passed as the method's second parameter. See the 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;
设置选中行的背景色
To solve the issue, disable the option.
标题
必须先添加列,才能有标题(标题是列标题,TreeList本身的Caption是不显示的)
添加节点图片
1.添加一个ImageCollection,控件名为imageCollection1 【多个form共用的话,可以使用】
按照节点的层级顺序添加图片
2. 设置TreeList的,,为imageCollection1
3. 注册TreeList的CustomDrawNodeImages事件
treeList1.CustomDrawNodeImages += TreeList1_CustomDrawNodeImages;private void TreeList1_CustomDrawNodeImages(object sender, CustomDrawNodeImagesEventArgs e){e.SelectImageIndex = e.Node.Level;}
NodeImage
概念:
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 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 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 property instead.