hi,
I ahve create a TreeView Control wiht check boxes:
I have created a parent Tree Node as:
Code
TreeNode parentNode = new TreeNode("Departments");
|
Then i have added four childNodes
Code
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....
C#
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
Kirtan PatelRank #292 · 8.6K reputationPosted Oct 31, 2009, 9:22 PM EDT
theLizardRank #1,079 · 1.8K reputationPosted Oct 31, 2009, 10:04 PM EDT
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