Hello,
Need a help from the forum..
I have a TreeView Control in my windows.forms coded in C#.I have a few parent nodes and each parent node as some child nodes. I wanted to get the number of Checked parents with their checked child nodes. Can you pls help me how do I get this ?
thanks,
Sree.
Loading
Vijay AnandPosted Nov 7, 2005, 5:29 AM
You can use the following code snippet to get the Checked Parent nodes and child nodes:
private void button1_Click(object sender, System.EventArgs e)
{
Recursion(this.treeView1.Nodes);
this.label1.Text="Parent Nodes : "+ParentNodes+"\n"+"Child Nodes :"+ChildNodes;
ParentNodes=0;
ChildNodes=0;
}
int ParentNodes=0,ChildNodes=0;
public void Recursion(TreeNodeCollection nodes)
{
if(nodes==null)
return;
foreach(TreeNode node in nodes)
{
if(node.Nodes.Count>0 && node.Checked)
{
ParentNodes++;
Recursion(node.Nodes);
}
else if(node.Checked)
{
ChildNodes++;
}
else if(node.Nodes.Count>0)
Recursion(node.Nodes);
}
}
I cant upload my test sample in this forum. So if you need that sample ask me to this mail id: [email protected].
let me know if you have any further question.
Thanks,
Vijay