我需要在treelist中实现增量搜索。标准是节点名称包含特定字符串。我发现这个建议“你应该覆盖的FindNode方法 XtraTreeList.Handler.TreeListHandler.IncrementalSearchState类“从这里http://community.devexpress.com/forums/t/15735.aspx。但我不明白如何实现这一点。
答案 0 :(得分:2)
一个简单的递归应该给出遍历整个树的解决方案。
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;
}
//---------------------------------------------------------------------------
现在,如果你做一个简单的调用,如:
TreeListNode node = GetNodeByName (treeList.Nodes, "MyNodeName");
您将获得所需的节点。
答案 1 :(得分:0)
我认为它类似于:
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);
}
}