Devexpress Treelist 过滤的实现



Devexpress Treelist 的过滤行添加后,发现,只有父节点有这种信息,子节点才会显示。

可以毫不犹豫地说,这是一个bug.

但带来的影响还是很严重。


我用的版本是11.2


然后,到网上,找了一会。

果然许多老外也遇到这个问题。

其中,这几个链接:

http://www.devexpress.com/Support/Center/Question/Details/S139453

内容最多。

其中,有句:

TreeListOptionsFilter.FilterMode property to theFilterMode.Smart value

这个例子就是如此实现,http://www.devexpress.com/Support/Center/Question/Details/B212393


        private void Form1_Load(object sender, EventArgs e)
        {
            treeList1.OptionsBehavior.EnableFiltering = true;
            treeList1.OptionsView.ShowAutoFilterRow = true;
            treeList1.OptionsFilter.FilterMode = FilterMode.Smart;
            CreateTreeList();
        }


然而,同样是11.2,我所用的没有这个特性。

我看了13.2的,的确有这个特性:

所以,还是希望找到一个简单的办法,

http://www.devexpress.com/Support/Center/Example/Details/E3072

这个链接事实上是上面那个给出来的

原文如下:

        private void Form1_Load(object sender, EventArgs e)
        {
            treeList1.DataSource = FillDataTable();
            treeList1.ExpandAll();
        }

        private void applyFilterButton_Click(object sender, EventArgs e)
        {
            FilterNodeOperation operation = new FilterNodeOperation(textEdit1.EditValue != null ? textEdit1.EditValue.ToString() : "");
            treeList1.NodesIterator.DoOperation(operation);
        }

        class FilterNodeOperation : TreeListOperation
        {
            string pattern;

            public FilterNodeOperation(string _pattern)
            { pattern = _pattern; }
            
            public override void Execute(TreeListNode node)
            {
                if (NodeContainsPattern(node, pattern))
                {
                    node.Visible = true;
                    if (node.ParentNode != null)
                        node.ParentNode.Visible = true;
                }
                else
                    node.Visible = false;
            }

            bool NodeContainsPattern(TreeListNode node, string pattern)
            {
                foreach (TreeListColumn col in node.TreeList.Columns)
                    if (node.GetValue(col).ToString().Contains(pattern))
                        return true;
                return false;
            }
        }

我改了改:

        private void treeList1_ColumnFilterChanged(object sender, EventArgs e)
        {
            //DevExpress.XtraTreeList.Nodes.TreeListNode fNode = treeList1.FocusedNode;
            //DevExpress.XtraTreeList.Columns.TreeListColumn fColumn = treeList1.FocusedColumn;
            if (treeList1.ActiveEditor != null)
            {
                string newKey = treeList1.ActiveEditor.EditValue.ToString();
                FilterNodeOperation operation = new FilterNodeOperation((!System.String.IsNullOrEmpty(newKey))?newKey : "");
                treeList1.NodesIterator.DoOperation(operation);
            }
            
        }  


终于可以了。


对了,原始代码,有这几句话:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraTreeList.Nodes.Operations;
using DevExpress.XtraTreeList.Columns;
using DevExpress.XtraTreeList.Nodes;




  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值