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.