I have a program with a TreeView list containing Nodes, and Nodes with Children. These all have the checkbox property enables. I need to know how to check what Nodes / node children are checked. So far I have been able to successfully test for the parent nodes, but no children using:
//this will turn black any node that is checked, doesn't affect the children though
TreeNodeCollection nodes = this.treeView1.Nodes;
foreach (TreeNode n in nodes)
{
if (n.Checked)
{
n.BackColor = Color.Black;
}
}
How do I get it to check the parent nodes, as well as the children? I have searched and not found anything that cleared this up for me.
You could define a recursive function that will mark all selected items:
and call it like so: