views:

31

answers:

2

I want to configure a treeview so that when all checkboxes of a parent are checked, then the parent checkbox is checked. And when all checkboxes are unchecked, the parent checkbox is unchecked. Does the treeview class have a standard property for that?

+1  A: 

Your requirement is incomplete, it doesn't say what should happen when some nodes are checked. Anyhoo, this kind is code is easy to get going with the AfterCheck event. For example:

private void treeView1_AfterCheck(object sender, TreeViewEventArgs e) {
  if (e.Node.Parent != null) {
    bool on = true;
    bool off = true;
    foreach (TreeNode node in e.Node.Parent.Nodes) {
      if (node.Checked) off = false;
      else on = false;
    }
    if (off) e.Node.Parent.Checked = false;
    if (on) e.Node.Parent.Checked = true;
  }
}
Hans Passant
A: 

Hi,

It can be done with JavaScript, please check out following link, it may help you to achieve what you want.

Check/Uncheck Treeview Checkbox

I hope it helps!! :)

Nil