expand treeview node when checkbox checked

J

jez123456

Hi Experts
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?

thanks
 
C

Cubicle Snowman

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();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top