Im setting up a new Form and Im having some issuis with the TreeViewNodes checking and uncheking the childs. Its easier to see the problem in this short clip
Normally it works properly but sometimes it gets stuck (I think there is a conflict with selection but Im not sure) and the methods arent applied properly.
I have this methods to check and uncheck the childs:
private void Treeview_AfterCheck(object sender, TreeViewEventArgs e)
{
if (e.Action != TreeViewAction.Unknown)
if (e.Node.Checked)
{
CheckAll(e.Node.Nodes);
}
if (e.Node.Checked == false)
{
Uncheckall(e.Node.Nodes);
}
}
public void Uncheckall(TreeNodeCollection nodes)
{
foreach (TreeNode node in nodes)
{
node.Checked = false;
foreach (TreeNode node1 in node.Nodes)
{
node1.Checked = false;
foreach (TreeNode node2 in node1.Nodes)
{
node2.Checked = false;
}
}
}
}
public void CheckAll(TreeNodeCollection nodes)
{
foreach (TreeNode node in nodes)
{
node.Checked = true;
foreach (TreeNode node1 in node.Nodes)
{
node1.Checked = true;
foreach (TreeNode node2 in node1.Nodes)
{
node2.Checked = true;
}
}
}
}
And I have tried to make the selection null:
private void TreeView_Select(object sender, TreeViewEventArgs e)
{
TreeView.SelectedNode = null;
}
But the problem remains. Any ideas? Thanks