基于v18.1
使用AppendNode方法手动赋值时,首先要添加treeListColumn
默认样式 修改后的样式
1 隐藏TreeList的列头
设置OptionsView下ShowColumns=False
2 隐藏竖直水平线
设置OptionsView下ShowHorzLines、ShowVertLines=False
3 隐藏左侧Node的指示符面板
设置OptionsView下ShowIndicator=False
4 禁止编辑节点
设置OptionsBehavior下Editable=False
5、 如何默认展开所有的节点, ExpandAll()
treeList1.ExpandAll();
以及TreeNode.Expand = false;
或者你可以控制展开的层数 treeList1.ExpandLevel = 10;
表示: 展开10层
// 第一层下的所有接点展开
treeList1.Nodes[0].ExpandAll();
6. 去掉边框
BorderStyle=NoBorder
添加节点方法
this.treeList1.BeginUnboundLoad(); this.treeList1.AppendNode(new object[] { "111"}, -1); this.treeList1.AppendNode(new object[] { "222"}, 0); this.treeList1.AppendNode(new object[] { "444"}, 1); this.treeList1.AppendNode(new object[] { "333"}, -1); this.treeList1.EndUnboundLoad();
节点折叠
treeList1.CollapseAll();
7.TreeList丢失焦点时,也处于高亮选中状态 (设置treeList节点的背景色)
treeList1.Appearance.FocusedCell.BackColor = System.Drawing.Color.LightSteelBlue;
treeList1.Appearance.FocusedCell.Options.UseBackColor = true; (默认是true)
二。treeList获取目录下的所有文件及文件夹
treeList1.Nodes.Clear(); TreeListNode rootNode= this.treeList1.AppendNode(new object[] { rootFilePath }, -1); TreeListNode firstNode = getRootListNode(treeList1, rootFilePath, 0);
private static TreeListNode getRootListNode(DevExpress.XtraTreeList.TreeList treeListFiles, string dirname, int nodeID) //递归,返回根结点 { if (!Directory.Exists(dirname)) return null; string[] dirs = Directory.GetDirectories(dirname); string[] files = Directory.GetFiles(dirname); foreach (string dir in dirs) { TreeListNode root2 = treeListFiles.AppendNode(new object[] { dir.Substring (dir.LastIndexOf('\')+1) }, nodeID); root2.Tag = dir; TreeListNode node2 = getRootListNode(treeListFiles, dir, root2.Id); } foreach (string file in files) { TreeListNode node2 = treeListFiles.AppendNode(new object[] { file.Substring (file.LastIndexOf('\')+1) }, nodeID, 1, 1, 0); node2.Tag = file; } return treeListFiles.Nodes.FirstNode; }