hi,
I ahve create a TreeView Control wiht check boxes:
I have created a parent Tree Node as:
TreeNode parentNode = new TreeNode("Departments");
|
Then i have added four childNodes
for(int i=0; i< 4; i++) { TreeNode childNode = new TreeNode(i.ToString()); parentNode.Nodes.add(childNode); } TreeViewControl.Nodes.add(parentNode)
|
Then i need to check all the childsNodes if parentNode is Checked so....
private void tvDepartments_AfterCheck(object sender, TreeViewEventArgs e) { if (e.Node.Name.ToString() == "parentNode") { foreach (TreeNode item in e.Node.Nodes) { item.Checked = true; } } }
|
The problem is that the control woudlnt go into the if statement... How do i fix this?
TY
theLizardPosted Nov 1, 2009, 2:04 AM
TreeNode p = TreeView1.Nodes.Add("Root");
TreeView1.CheckBoxes = true;
for (int i = 0; i < 10; i++)
{
TreeNode n = new TreeNode();
n.Checked = true;
n.Text = "Child" + i.ToString();
p.Nodes.Add(n);
}
private void TreeView1_AfterCheck(object sender, TreeViewEventArgs e)
{
if (e.Node.Text == "Root")
{
for (int i = 0; i < e.Node.Nodes.Count; i++)
{
e.Node.Nodes[i].Checked = true;
//alternately this toggles the check state based on parents state.
e.Node.Nodes[i].Checked = e.Node.Nodes[i].Parent.Checked;
}
}
}
After thought, this
Kirtan PatelPosted Nov 1, 2009, 1:22 AM