DevExpress TreeList incremental search
I need to implement incremental sea开发者_高级运维rch in treelist. The criterion is node's name contain specific string. I found this advise "You should override the FindNode method of the XtraTreeList.Handler.TreeListHandler.IncrementalSearchState class" from here http://community.devexpress.com/forums/t/15735.aspx. But i don't understand how to realize this.
A simple recursive should give a solution to traverse the whole tree.
private TreeListNode GetNodeByName(TreeListNodes prmNodes, String prmName)
{
foreach (TreeListNode node in prmNodes)
{
// Assume the data is present in column 0.
if (node[0].ToString().Contains(prmName, StringComparison.CurrentCultureIgnoreCase))
return node;
TreeListNode foundNode = GetNodeByName(node.Nodes, prmName);
if (foundNode != null)
return foundNode;
}
return null;
}
//---------------------------------------------------------------------------
Now if you do a simple call like:
TreeListNode node = GetNodeByName (treeList.Nodes, "MyNodeName");
you will get your desired node.
I think it's something like:
public class MyTreeList : DevExpress.XtraTreeList.TreeList
{
protected override DevExpress.XtraTreeList.Handler.TreeListHandler CreateHandler()
{
return new MyHandler(this);
}
internal DevExpress.XtraTreeList.Handler.TreeListHandler GetHandler() { return this.Handler; }
}
public class MyHandler : DevExpress.XtraTreeList.Handler.TreeListHandler
{
public MyHandler(TreeList tree) : base(tree) { }
protected override TreeListControlState CreateState(TreeListState state)
{
if (state == TreeListState.IncrementalSearch && this.TreeList is MyTreeList)
return new MyFinder((this.TreeList as MyTreeList).GetHandler());
return base.CreateState(state);
}
}
public class MyFinder : DevExpress.XtraTreeList.Handler.TreeListHandler.IncrementalSearchState
{
public MyFinder(DevExpress.XtraTreeList.Handler.TreeListHandler handler) : base(handler) { }
protected override TreeListNode FindNode(FindNodeArgs e)
{
////////////////////////////////////
////////////////////////////////////
////////////////////////////////////
return base.FindNode(e);
}
}
精彩评论