devxlogo

A Better Way to Validate a Node Checkbox in a Treeview

A Better Way to Validate a Node Checkbox in a Treeview

You cannot change the value of a nodes checkbox in the event treeview_NodeCheck as explained in this tip. Besides that, the event doesn’t fire at all when clicking a nodes checkbox and dragging the mouse out of the treeview before releasing your mousebutton.

The following code is a decent work-around:

Private Sub treeview_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)    Dim objNode As MSComctlLib.Node    Set objNode = treeview.HitTest(x, y)    If Not objNode Is Nothing Then Set treeview.SelectedItem = objNodeEnd SubPrivate Sub treeview_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)    'Do whatever validation you want on treeview.SelectedItem    'You might want to check here for a not set SelectedItemEnd Sub
See also  5 Tips for Working With an Onsite Interpreter
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist