search inside the tree

Hi
I am building a tree using tree view in c#
I would like to ask how could I search inside the tree for a parent node
and how could I search for the childeren inside the parent

to make this clear
if I have A is a parent for B & C
and C (is different than the C with A) is a parent for D & F
A & C are in the same level
so how could I search for C and retrive for me only the parent, not the child with A

and how could I search withen the children with a specific parent

thanks in advance
suzan_Asked:
Who is Participating?
 
BinuthConnect With a Mentor Commented:

try
			{
				TreeNode[] tn = treeView1.Nodes.Find("C" , false);
 
				for (int i = 0; i < tn.Length; i++)
				{
					treeView1.SelectedNode = tn[i];
					treeView1.SelectedNode.BackColor = Color.Yellow;
				}
			}
			catch { }

Open in new window

0
 
BinuthCommented:
first set Name & text for each Tree Nodes

and use

treeView1.Nodes.Find("C",false);
0
 
suzan_Author Commented:
thanks for your response

this is my search function

           try
    {
        TreeNode[] tn = treeView1.Nodes[0].Nodes.Find("C", true);
               
        for (int i = 0; i < tn.Length; i++)
        {
            treeView1.SelectedNode = tn[i];
            treeView1.SelectedNode.BackColor = Color.Yellow;  
        }
    }
    catch { }
        }

the tree looks like this
A
       B
       C     <<<<

G
C        <<< i want this C
      D
      F

so I want to search in the first level
then when I found it i need to search withen its childeren

thanks again for your help
0
 
suzan_Author Commented:
thanks a lot Binuth
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.