0
我正在使用infragistics工具處理C#.Net項目。在我的項目中,我想實現搜索選項,如Microsoft Office Outlook 2007搜索功能。如何在c#.net中搜索類似於Outlook的treenode文本?
我正在使用infragistics工具處理C#.Net項目。在我的項目中,我想實現搜索選項,如Microsoft Office Outlook 2007搜索功能。如何在c#.net中搜索類似於Outlook的treenode文本?
舉例說明一個使用System.Windows.Forms.TreeView的例子。假設Infragistics樹視圖可以做同樣的事情。關鍵是在使用樹時使用遞歸方法:
// Returns the node with the first hit, or null if none
public TreeNode Search(TreeView treeView, string text)
{
return SearchNodes(treeView.Nodes, text);
}
// Recursive text search depth-first.
private TreeNode SearchNodes(TreeNodeCollection nodes, string text)
{
foreach (TreeNode node in nodes)
{
if (node.Text.Contains(text)) return node;
var subSearchHit = SearchNodes(node.Nodes, text);
if (subSearchHit != null) return subSearchHit;
}
return null;
}
你到底在問什麼?搜索算法或GUI部分的實現 - 檢索輸入和顯示搜索結果? – Nilzor
搜索算法 –