Wednesday, May 02, 2007

How to lock checkbox on Treeview

When you have a Treeview ActiveX control with checkboxes it could be required to prevent checking or un-checking certain nodes. Unfortunately you can not do this in NodeCheck event, but MouseUp event could help here.

Declare a form class level variable:

Private cNode as Node

In NodeCheck set it to a node you want to lock (in this sample – bold node):

If Node.Bold=True Then Set cNode = NodeEnd If

And reset it to original state in MouseUp event:

If Not cNode Is Nothing Then cNode.Checked = true Set cNode = NothingEnd If