Forum  General Visual ...  How do I...?  Recursive search in tree view in C#
Previous   Previous
 
Next   Next
New Post  2/15/2009 10:08 PM
   YossiA
2 posts
No Ranking


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

 
New Post  2/16/2009 8:49 AM
   Ewans
530 posts
1st Level Poster




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;
            }           
        }
 

 
New Post  2/16/2009 10:54 PM
   YossiA
2 posts
No Ranking


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

 
New Post  2/17/2009 12:09 AM
   Ewans
530 posts
1st Level Poster




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

 

 
New Post  2/19/2009 5:56 AM
   dror.shahak
302 posts
3rd Level Poster




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
 
Previous   Previous
 
Next   Next
  Forum  General Visual ...  How do I...?  Recursive search in tree view in C#
.NET HTML5 Web, Cloud and Mobile application delivery | Sitemap | Terms of Use | Privacy Statement | Copyright © 2005-2012 Visual WebGui®       Visual WebGui weblog on ASP.NET Gizmox Blog Visual WebGui Group on LinkedIn Visual WebGui updates on Twitter Visual WebGui Page on Facebook Visual WebGui YouTube Channel Visual WebGui Platform News RSS