Use TreeView Control With Checkboxes

Use TreeView Control With Checkboxes

When the NodeCheck event triggers, you receive as a parameter the node that was checked. Say you need to do some validation and uncheck the node when there’s an error. You set Node.Checked = False, right? Wrong! That unchecks the node until the NodeCheck event finishes, but at the end of the event, the node changes to its previous value. The reason for that is that the Node parameter is passed ByVal. To work around this problem, add a timer to your form (Interval=50, Enabled=False). Enable the timer in the NodeCheck event:

 Dim mNode As NodePrivate Sub Timer1_Timer()	Timer1.Enabled = False	mNode.Checked = False	Set mNode = NothingEnd SubPrivate Sub TreeView1_NodeCheck(ByVal Node As MSComctlLib.Node)	If Node.Checked Then		'...If Invalid Then...		MsgBox "This Node Cannot be Checked."		Set mNode = Node		Timer1.Enabled = True	End IfEnd Sub
See also  11 Effective Keyword Research Tools and Techniques

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