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

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

 

posted @ 2017-10-06 19:23  守望阳光01  阅读(623)  评论(0编辑  收藏  举报