场景

Winform控件-DevExpress18下载安装注册以及在VS中使用:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/100061243

DevExpress的TreeList怎样设置数据源,从实例入手:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/102548490

在上面实现简单的TreeList并设置数据源,显示效果仍然不是想要的树形结构的效果。

如果想实现如下这样效果,还需要进行进一步的属性设置。

注:

博客主页:
https://blog.csdn.net/badao_liumang_qizhi

关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。

实现

   /// 为树控件设置数据源
/// </summary>
/// <param name="treeList">树控件</param>
/// <param name="data">数据对象</param>
/// <param name="fieldName">显示的字段</param>
/// <param name="keyFieldName">键字段</param>
/// <param name="parentFieldName">父级键字段</param>
public static void SetTreeListDataSource(DevExpress.XtraTreeList.TreeList treeList, List<DataTreeNode> data, string fieldName, string keyFieldName, string parentFieldName)
{
#region 设置节点图标 System.Windows.Forms.ImageList imgList = new System.Windows.Forms.ImageList();
imgList.Images.AddRange(imgs); treeList.SelectImageList = imgList; //目录展开
treeList.AfterExpand -= treeList_AfterExpand;
treeList.AfterExpand += treeList_AfterExpand; //目录折叠
treeList.AfterCollapse -= treeList_AfterCollapse;
treeList.AfterCollapse += treeList_AfterCollapse; //数据节点单击,开启整行选中
treeList.MouseClick -= treeList_MouseClick;
treeList.MouseClick += treeList_MouseClick; //数据节点双击选中
treeList.MouseDoubleClick -= treeList_MouseDoubleClick;
treeList.MouseDoubleClick += treeList_MouseDoubleClick; //焦点离开事件
treeList.LostFocus -= treeList_LostFocus;
treeList.LostFocus += treeList_LostFocus; #endregion #region 设置列头、节点指示器面板、表格线样式 treeList.OptionsView.ShowColumns = false; //隐藏列标头
treeList.OptionsView.ShowIndicator = false; //隐藏节点指示器面板 treeList.OptionsView.ShowHorzLines = false; //隐藏水平表格线
treeList.OptionsView.ShowVertLines = false; //隐藏垂直表格线
treeList.OptionsView.ShowIndentAsRowStyle = false; #endregion #region 初始禁用单元格选中,禁用整行选中 treeList.OptionsView.ShowFocusedFrame = true; //设置显示焦点框
treeList.OptionsSelection.EnableAppearanceFocusedCell = false; //禁用单元格选中
treeList.OptionsSelection.EnableAppearanceFocusedRow = false; //禁用正行选中
//treeList.Appearance.FocusedRow.BackColor = System.Drawing.Color.Red; //设置焦点行背景色 #endregion #region 设置TreeList的展开折叠按钮样式和树线样式 treeList.OptionsView.ShowButtons = true; //显示展开折叠按钮
treeList.LookAndFeel.UseDefaultLookAndFeel = false; //禁用默认外观与感觉
treeList.LookAndFeel.UseWindowsXPTheme = true; //使用WindowsXP主题
treeList.TreeLineStyle = DevExpress.XtraTreeList.LineStyle.Percent50; //设置树线的样式 #endregion #region 添加单列 DevExpress.XtraTreeList.Columns.TreeListColumn colNode = new DevExpress.XtraTreeList.Columns.TreeListColumn();
colNode.Name = String.Format("col{0}", fieldName);
colNode.Caption = fieldName;
colNode.FieldName = fieldName;
colNode.VisibleIndex = ;
colNode.Visible = true; colNode.OptionsColumn.AllowEdit = false; //是否允许编辑
colNode.OptionsColumn.AllowMove = false; //是否允许移动
colNode.OptionsColumn.AllowMoveToCustomizationForm = false; //是否允许移动至自定义窗体
colNode.OptionsColumn.AllowSort = false; //是否允许排序
colNode.OptionsColumn.FixedWidth = false; //是否固定列宽
colNode.OptionsColumn.ReadOnly = true; //是否只读
colNode.OptionsColumn.ShowInCustomizationForm = true; //移除列后是否允许在自定义窗体中显示 treeList.Columns.Clear();
treeList.Columns.AddRange(new DevExpress.XtraTreeList.Columns.TreeListColumn[] { colNode }); #endregion #region 绑定数据源 treeList.KeyFieldName = keyFieldName;
treeList.ParentFieldName = parentFieldName;
treeList.DataSource = data;
treeList.RefreshDataSource(); #endregion #region 初始化图标 SetNodeImageIndex(treeList.Nodes.FirstOrDefault()); #endregion
}

DevExpress的TreeList的常用属性设置以及常用事件的更多相关文章

  1. unigui的ServerModule常用属性设置

    unigui的ServerModule常用属性设置 1)压缩设置 compression是压缩数据用的.默认启用压缩,且压缩级别是最大的. 2)UNIGUI运行时库设置 UNIGUI需要4个运行时库, ...

  2. Android中TextView和EditView常用属性设置

    Android中TextView和EditView常用属性设置 点击跳转

  3. DEV控件:gridControl常用属性设置(转载)

    特别长,先撸下来再说 1.隐藏最上面的GroupPanel  gridView1.OptionsView.ShowGroupPanel=false; 2.得到当前选定记录某字段的值  sValue=T ...

  4. DEV控件:gridControl常用属性设置

    1.隐藏最上面的GroupPanel  gridView1.OptionsView.ShowGroupPanel=false; 2.得到当前选定记录某字段的值  sValue=Table.Rows[g ...

  5. DEV控件GridControl常用属性设置

    1. 如何解决单击记录整行选中的问题 View->OptionsBehavior->EditorShowMode 设置为:Click 2. 如何新增一条记录 (1).gridView.Ad ...

  6. DEV控件GridControl常用属性设置(转)

      1. 如何解决单击记录整行选中的问题 View->OptionsBehavior->EditorShowMode 设置为:Click 2. 如何新增一条记录 (1).gridView. ...

  7. 【iOS】UILabel 常用属性设置

    UILabel 的一些常用属性,示例代码如下: // 字体大小 label.font = [UIFont systemFontOfSize:14.0]; label.font = [UIFont fo ...

  8. Mysql 整数类型的字段的属性设置及常用的函数

    数据类型 二.MySQL支持的数据类型 数值类型.日期类型.字符串类型 1.数值类型 1)整数类型 tinyint.smallint.mediumint.int和bigint 2)zerofill属性 ...

  9. TX Textcontrol 使用总结六——常用属性设置

    1.字体设置 Tx textcontrol字体设置以版本22为例,直接设置FontSize =int,字体大小将小于正常其他控件字体设置.应做如下处理(仅供参考) this.textControl1. ...

随机推荐

  1. Socket简单实现ssh笔记

    Scoket概念: socket本质上就是在2台网络互通的电脑之间,架设一个通道,两台电脑通过这个通道来实现数据的互相传递. 我们知道网络 通信 都 是基于 ip+port 方能定位到目标的具体机器上 ...

  2. Python单元测试工具doctest和unittest

    Python标准库包含两个测试工具. doctest:一个简单的模块,为检查文档而设计,但也适合用来编写单元测试. unittest:一个通用的测试框架. 一.使用doctest进行单元测试 创建文件 ...

  3. rocksdb和leveldb性能比较——写性能

    前面学习了一下rocksdb,这个db是对leveldb的一个改进,是基于leveldb1.5的版本上的改进,而且leveldb1.5以后也在不断的优化,下面从写入性能对两者进行对比. 前言 比较的l ...

  4. Python—实现ssl认证

    https://blog.csdn.net/vip97yigang/article/details/84721027 https://www.cnblogs.com/lsdb/p/9397530.ht ...

  5. Python—版本和环境的管理工具(Pipenv)

    pipenv简介 虚拟环境本质是一个文件,是为了适应不同的项目而存在.pipenv相当于virtualenv和pip的合体. 整合了 pip+virtualenv+Pipfile,能够自动处理好包的依 ...

  6. ambassador对websocket的支持示例

    今天进展神速,ambassador对websocket的支持也调通啦.. 一,关键yaml文件 --- apiVersion: v1 kind: Service metadata: labels: n ...

  7. 【西北师大-2108Java】第二次作业成绩汇总

    2[西北师大-2108Java]第二次作业成绩汇总 以命令行方式或在Eclipse集成开发环境中编辑.编译.运行第3章示例程序3-1-3-5,结合程序运行结果理解程序代码,每个示例程序从语法.算法两个 ...

  8. Keras:

    https://keras.io/zh/layers/core/ keras使用稀疏输入进行训练 2018.06.14 12:55:46字数 902阅读 760 稀疏矩阵 稀疏矩阵是指矩阵中数值为0的 ...

  9. vue-cli2 打包

    npm run build 打包安装 相当于静态资源 解决vue-cli项目打包出现空白页和路径错误的问题 路径错误的问题解决方式: 打开config文件夹下的 index.js 找到如下图所示区域: ...

  10. Django cache (缓存)

    五种配置 1.开发调试 # 此为开始调试用,实际内部不做任何操作 # 配置: CACHES = { 'default': { 'BACKEND': 'django.core.cache.backend ...