Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Feb 24, 2000

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 Node
Private Sub Timer1_Timer()
	Timer1.Enabled = False
	mNode.Checked = False
	Set mNode = Nothing
End Sub
Private 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 If
End Sub
Gerardo Villeda
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap