1

I am using the Tri-State Tree View which inherits from TreeView.

http://www.codeproject.com/Articles/202435/Tri-State-Tree-View

It is clear for me how I can grey out the text: TreeView with multi-color TreeNode text

Using the described event handler, I can easily change the text color of specific items in the ri-State Tree View. However, how can I change the color of specific checkboxes in the Tri-State Tree View so it looks like they are greyed out/disabled ?

Please note that I am using the treeview from code project, not the general TreeVieuw: Disable and grey out a check box of treenode

Community
  • 1
  • 1
Daan
  • 2,478
  • 3
  • 36
  • 76

1 Answers1

1

In your case there is no easy/quick way because the TreeNode does not have an Enabled property. You will have to add this functionnality yourself. I took a look at the TriStateTreeView code and I can make some remarks to help you.

The drawing part will be easy, you will find in the constructor :

case 0: CheckBoxRenderer.DrawCheckBox(chkGraphics, new Point(0, 1), CheckBoxState.UncheckedNormal);
break;
case 1: CheckBoxRenderer.DrawCheckBox(chkGraphics, new Point(0, 1), CheckBoxState.CheckedNormal);
break;
case 2: CheckBoxRenderer.DrawCheckBox(chkGraphics, new Point(0, 1), CheckBoxState.MixedNormal);
break;

this part fills the StateImageList that will store the bitmaps for every possible state. You will need to add three other pictures which already exist in System.Windows.Forms.VisualStyles : CheckBoxState.UncheckedDisabled, CheckBoxState.CheckedDisabled, and CheckBoxState.MixedDisabled.

Then when you want to affect for instance the CheckedDisabled appearence to the node, you will need to change the StateImageIndex of the TreeNode property, like this myNode.StateImageIndex = (int)CheckedState.CheckedDisabled;

The more complex part will be the implementation of the logic. The TriStateTreeView only overrides five events from the Windows.Forms.TreeView , you will need to change them to handle your new functionnality. You will probably have to add something like this in the top : if(e.Node.StateImageIndex == (int)CheckedState.CheckedDisabled || ... ) return; but it may not be that simple in every case so make sure you check every method.

KVM
  • 878
  • 3
  • 13
  • 22