[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 193
  • Last Modified:

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
0
suzan_
Asked:
suzan_
  • 2
  • 2
1 Solution
 
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
 
suzan_Author Commented:
thanks a lot Binuth
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now