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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
BinuthCommented:

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
suzan_Author Commented:
thanks a lot Binuth
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.