AccessBlog.net

News, links, downloads, tips and tricks on Microsoft Access and related

About Me Search
Alex
Name:Alex Dybenko

Location:Moscow, Russia

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 = 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

Technorati tags: , ,

2 Comments:

Anonymous Anonymous said...

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

11:45 AM  
Blogger Alex Dybenko said...

Thanks, but this was a post on AcitveX Treeview, not a winforms one

11:48 AM  

Post a Comment

Links to this post:

Create a Link

<< Home