2

Possible Duplicate:
TreeView Remove CheckBox by some Nodes

In my C# Windows Form Application, I have Treeview control with checkboxes.

I want to prevent the user from checking particular nodes' checkboxes. How can stop the user from being able to check particular ones?

Community
  • 1
  • 1
Saravanan
  • 11,372
  • 43
  • 143
  • 213

1 Answers1

1

TreeView.AfterCheck Event is one option to prevent checking nodes. I find this is an easy way of doing it. But there can be better ways.

private void node_AfterCheck(object sender, TreeViewEventArgs e)
{
   // The code only executes if the user caused the checked state to change.
   if(e.Action != TreeViewAction.Unknown)
   {
      if(e.Node.Nodes.Count > 0)
      {
         //Check whether that is a valid checkbox
         // If not you can uncheck it.
      }
   }
}

Edit

To hide the checkboxes. Look at Cody Gray's answer here.

Community
  • 1
  • 1
CharithJ
  • 46,289
  • 20
  • 116
  • 131
  • We dont allow the user to check the check box.While creating that particullar tree node, i want to create the specific tree node with check box disabled. – Saravanan Aug 26 '11 at 11:55
  • Why don't you hide checkboxes rather than disabling as you have asked in other question. Again this may help you http://stackoverflow.com/questions/4826556/treeview-remove-checkbox-by-some-nodes – CharithJ Aug 26 '11 at 11:59
  • My thought is exactly what u said...Is this possible? – Saravanan Aug 26 '11 at 12:01
  • @ Saravanan : Look at here. This should work. http://stackoverflow.com/questions/4826556/treeview-remove-checkbox-by-some-nodes/4826740#4826740 – CharithJ Aug 26 '11 at 12:06
  • @ Sarvanan : I've updated my answer with the link to Cody Gray's answer. – CharithJ Aug 27 '11 at 06:43