Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 22nd, 2005, 05:54 AM
Authorized User
 
Join Date: Jul 2003
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Default Treeview Manipulation

1. We have selectedNode but how do we get the checked node that wasn't Selected?

2. How do we get the parent node of the checked node?

3. How do we not allow a parent node uncheked whose child is checked?

Thank in advance

Proud To Be Pinoy
__________________
Proud To Be Pinoy
 
Old March 22nd, 2005, 12:02 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

I'm guessing, but I believe you are going to have to “walk the tree,” recursively following each branch, and checking the properties of each node.

I believe each node but the root node has a .Parent property.

It is likely to be easiest to just keep track of all changes to the tree (storing values in variables to represent the tree), starting from a known position when the program initially runs.
Then you can permit (or not) checking a node based on the information you have stored, rather than through “reading” the tree all over again.

What does it mean to be Pinoy?
 
Old March 22nd, 2005, 04:59 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

The Treeview has a BeforeSelect event where you can place a for...next loop to scan the nodes.
You can get the parent by using e.Node.Parent (as Brian stated) which is passed in the Treeview arguments. You can look for a checked child like this:

If e.Node.Nodes.Count >= 1 And e.Node.Checked = True Then
     Dim tnode As New TreeNode
     For Each tnode In e.Node.Nodes
         If tnode.Checked Then
             MessageBox.Show("Child is checked.")
             e.Cancel = True 'cancels the check event
             Exit For 'exit the loop when one is found
         End If
     Next
End If


This should get you started, but as Brian said it needs to be recursive in order to scan nodes deeper than 1 level.

J

P.S. - Pinoy means Filipino.
 
Old March 22nd, 2005, 09:15 PM
Authorized User
 
Join Date: Jul 2003
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks guys, Ill try it out.

Proud To Be Pinoy
 
Old March 23rd, 2005, 05:03 AM
Authorized User
 
Join Date: Jul 2003
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The code was ok except for the "e.Cancel" part, I treeview eventargs doesnt support it.
Mine is VB.Net Std 2002 with SP2(?)

How can I add "e.cancel" because it just loops till an exception?


Proud To Be Pinoy
 
Old March 23rd, 2005, 09:55 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

What exception are you getting? The code that I gave you should exit the loop when a check is found on a child node. Are you sure that the exception is not caused by something executing after you exit the loop?

J
 
Old March 28th, 2005, 01:02 AM
Authorized User
 
Join Date: Jul 2003
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My problem is that my treeview in VB.Net 2002 Std Ed. doesn't have "e.cancel".

After I type the "." operator I cant find the "Cancel" Method





Proud To Be Pinoy
 
Old March 28th, 2005, 09:43 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

The e.Cancel essentially cancels out the check change without additional code by you. Since, apparently, .Net 2002 doesn't support this you can simply set "e.Node.Checked = True" and exit the loop.

J





Similar Threads
Thread Thread Starter Forum Replies Last Post
String manipulation pcase XSLT 5 June 14th, 2007 10:32 AM
Date Manipulation pallone Javascript How-To 2 May 5th, 2006 02:15 PM
Date manipulation otarboy Access 1 September 20th, 2004 11:50 AM
Time manipulation rajanikrishna Classic ASP Databases 1 May 11th, 2004 03:03 AM
String Manipulation twsinc Access 3 February 23rd, 2004 09:57 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.