VB6 How to disable tree view checkboxes in nodes ?

The MSComctlLib Treeview control has a property to show checkboxes for each nodes.
Unfortunately it is not possible to disable the check boxes selectively for some nodes

A solution consist in to not use the standard check boxes and replace them with custom images

(e.g: http://www.codeproject.com/Questions/621261/How-to-subclass-tree-view-control-to-show-or-hide)

Here my solutions:

1) add a module variable

Private curNode_clicked As MSComctlLib.Node

2) in the NodeCheck event of the Treeview write the condition in order to permit or not to check (uncheck) the node

Private Sub TrvDettaglio_NodeCheck(ByVal Node As MSComctlLib.Node)    
    Set curNode_clicked = Nothing
    If Node.Tag = "DISABLED" Then
        Set curNode_clicked = Node
        MsgBox "Node Disabled !!!"
        Exit Sub
    End If
End Sub    

3) in the MouseUp event reverse the checked value of the Node

Private Sub TrvDettaglio_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
    If Not curNode_clicked Is Nothing Then
        curNode_clicked.Checked = Not curNode_clicked.Checked
    End If
End Sub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s