I have a windows form with a TreeView control with the CheckBoxes property
set to True.
When I check a node, I want that node and all it's child nodes to be checked
and expanded.
I've tried various things but none seem to work correctly.
Any ideas?
I did a quick testing and following seemed to do what you wanted:
Create eventhandler for TreeView.AfterCheck -event.
You can get the checked node from TreeViewEventArgs. Let's assume e.
if (!e.Node.Checked)
{
foreach (TreeNode child in e.Node.Nodes)
{
child.Checked = false;
}
e.Node.Collapse(false);
}
else
{
foreach (TreeNode child in e.Node.Nodes)
{
child.Checked = true;
}
e.Node.ExpandAll();
}