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 = Node
End If  
And reset it to original state in MouseUp event:
If Not cNode Is Nothing Then
     cNode.Checked = true
    Set cNode = Nothing
End If  






 
					

2 Comments:
There is a possibility to do this very simple way:
Private Sub treeView_BeforeCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles treeView.BeforeCheck
e.Cancel = True 'Cancels checkbox action
End Sub
Thanks, but this was a post on AcitveX Treeview, not a winforms one
Post a Comment
<< Home