|
SearchForum Home |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Recursive search in tree view in C# |
|
|
Hi,
I tryied to implement a recursive search in a tree without success.
For example my tree display 3 levels: root, parents and children. I need to return as result a new tree with only the children (and parets of course) that have specific string in their names.
Can anyone help me with this problem?
Thanks a lot,
Yossi, SAP
|
|
|
|
|
|
|
|
Re: Recursive search in tree view in C# |
|
|
Hi YossiA
Try
private void FindNodeInHierarchy(TreeNodeCollection nodes, string strSearchValue)
{
for (int iCount = 0; iCount < nodes.Count; iCount++)
{
if (nodes[iCount].Text.ToUpper().Contains(strSearchValue.ToUpper()))
{
trvSourceCode.SelectedNode = nodes[iCount];
trvSourceCode.Select();
m_bNodeFound = true;
return;
}
else
{
m_bNodeFound = false;
}
//expand the nodes
nodes[iCount].Expand();
//Recursively search the text in the child nodes
FindNodeInHierarchy(nodes[iCount].Nodes, strSearchValue);
if (m_bNodeFound)
{
return;
}
//collapses the nodes
nodes[iCount].Collapse();
//return;
}
}
|
|
|
|
|
|
|
|
Re: Recursive search in tree view in C# |
|
|
Hi Ewans,
Thanks a lot for your time and solution.
It works fine and get results, I have a little problem in using this solution because i need to draw a new tree with all the nodes that contains the string that i search.
for example:
Company
DEV
Yoni
Cris
Mark
QA
Yossi
Alex
Serah
Danna
QM
Josef
If I search for "yo"
The new tree should return:
Company
DEV
Yoni
QA
Yossi
Thanks,
Yossi
|
|
|
|
|
|
|
|
Re: Recursive search in tree view in C# |
|
|
Hi Yossi
each node has a level (node.level) which tells you how far down the tree it is, so what you need to do is when you have found the leaf node, is to build the new tree starting with the first ancestor an then add the descendants
for example node.parent.text will return DEV if the Leaf is Yoni
node.parent.parent.text will return Company.
Hope this helps
Ewan
|
|
|
|
|
|
|
|
Re: Recursive search in tree view in C# |
|
|
Hi Yossi,
I think you might be in the wrong forum. As we're emulation Winfroms, I think you can find better results in a 'non-VWG' Forum but microsofts, say - winforms or CS.
Good Luck
Dror Shahak
The Visual WebGui Team
Dror Shahak, The Visual WebGui Team
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|