If you want to check
Treeview
control's only one node for each root node, you can use this:
private void treeview1_AfterCheck(object sender, TreeViewEventArgs e)
{
if (e.Node.Checked)
{
DiselectParentNodes(e.Node.Parent);
DiselectChildNodes(e.Node.Nodes);
}
}
private void DiselectParentNodes(TreeNode parent)
{
while (parent != null)
{
if (parent.Checked)
parent.Checked = false;
parent = parent.Parent;
}
}
private void DiselectChildNodes(TreeNodeCollection childes)
{
foreach (TreeNode oneChild in childes)
{
if (oneChild.Checked)
oneChild.Checked = false;
DiselectChildNodes(oneChild.Nodes);
}
}