关于dev的treelist的表头 获取集合 bands 或者 columns 来设置标题换行

使用treelsit时我们可能会应用到给标题换行,如果涉及到多级标题呢?类似于:
在这里插入图片描述
直接使用treelist.bands只能获取到一级标题,也就是表中预算收入band,不能获取到二级标题 预算收入工程直接费 和 三级标题 人工费 等!

解决方案:
遍历bands,得到一级标题,在通过bands子集去判断是否还有子子集,也就是用递归去取所有band!
这是实现思路!代码我实现了一个公共方法!
1.设置bands或者columns 的caption换行处添加一个转义字符或者使用特殊字符来做换行处理!(此处使用为特殊字符:※ 可自定)
例:
在这里插入图片描述
2.只需要传入treelist即可!
代码:

/// <summary>
        /// 设置treelist标题换行
        /// </summary>
        /// <param name="treeList"></param>
        public static void SetTreelistBandRow(TreeList treeList)
        {
            List<TreeListBand> listBands = new List<TreeListBand>();
            if (treeList.Bands.Count() > 0)//有bands在执行
            {
                treeList.BandPanelRowHeight = 40;
                foreach (TreeListBand band in treeList.Bands)
                {
                    GetBands(band, listBands);
                }
                if (listBands.Count > 0)
                {
                    foreach (TreeListBand item in listBands)
                    {
                        if (item.Caption.IndexOf("※") > 0)
                        {
                            item.AppearanceHeader.TextOptions.WordWrap = DevExpress.Utils.WordWrap.Wrap;
                            item.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
                            string bandcaption = item.Caption.Replace("※", "\n");
                            item.Caption = bandcaption;
                        }
                    }
                }
                return;
            }

            if (treeList.Columns.Count() > 0)//有Columns在执行
            {
                treeList.ColumnPanelRowHeight = 50;
                foreach (TreeListColumn col in treeList.Columns)
                {
                    if (col.Caption.IndexOf("※") > 0)
                    {
                        col.AppearanceHeader.TextOptions.WordWrap = DevExpress.Utils.WordWrap.Wrap;
                        col.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
                        string bandcaption = col.Caption.Replace("※", "\n");
                        col.Caption = bandcaption;
                    }
                }
            }

        }
        /// <summary>
        /// 递归获取bands集合
        /// </summary>
        /// <param name="band"></param>
        /// <param name="listBands"></param>
        public static void GetBands(TreeListBand band, List<TreeListBand> listBands)
        {
            listBands.Add(band);
            if (band.Bands.Count() > 0)
            {
                foreach (TreeListBand item in band.Bands)
                {
                    GetBands(item, listBands);
                }
            }
        }

注意:如果出现标题文本位置在单元格偏上则说明行高设置的不够!

调用:

SetTreelistBandRow(treelist);
微信扫码订阅
UP更新不错过~
关注
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Mark_mwl

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值