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
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: