dev treelist和searchcontrol组合模糊查询用法

这里需要用到两个控件,是dev的treelist和searchcontrol,首先呢树形控件要形成树形我在这就不多说了 

因为这里是记录下searchcontrol这控件的用法

首先写这三行代码,里面都有注释

this.searchControl1.Client = this.treeList1;//设置搜索绑定
            treeList1.OptionsBehavior.EnableFiltering = true;//开启过滤功能
            treeList1.OptionsFilter.FilterMode = FilterMode.Smart;//过滤模式
View Code

然后我们构造一个事件,我们称它为过滤事件,

//过滤事件
            treeList1.FilterNode += treeList1_FilterNode;

然后在事件中写上代码

void treeList1_FilterNode(object sender, DevExpress.XtraTreeList.FilterNodeEventArgs e)
        {
            if (treeList1.DataSource == null) return;
            string NodeText = e.Node.GetDisplayText("SCNAME");
            if (string.IsNullOrWhiteSpace(NodeText)) return;
            bool IsVisible = NodeText.ToUpper().IndexOf(searchControl1.Text.ToUpper()) >= 0;
            if (IsVisible)
            {
                TreeListNode Node = e.Node.ParentNode;
                while (Node != null)
                {
                    if (!Node.Visible)
                    {
                        Node.Visible = true;
                        Node = Node.ParentNode;
                    }
                    else
                        break;
                }
            }
            e.Node.Visible = IsVisible;
            e.Handled = true;
        }
View Code

到这里,如果你的树形数据没有问题的话,就能看到效果了 ,快去动手试试吧

 

转载于:https://www.cnblogs.com/liuhuimh/p/7632040.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值