Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 22nd, 2005, 05:54 AM
Authorized User
 
Join Date: Jul 2003
Location: Davao, , Philippines.
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
Reply With Quote
  #2 (permalink)  
Old March 22nd, 2005, 12:02 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
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?
Reply With Quote
  #3 (permalink)  
Old March 22nd, 2005, 04:59 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
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.
Reply With Quote
  #4 (permalink)  
Old March 22nd, 2005, 09:15 PM
Authorized User
 
Join Date: Jul 2003
Location: Davao, , Philippines.
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks guys, Ill try it out.

Proud To Be Pinoy
Reply With Quote
  #5 (permalink)  
Old March 23rd, 2005, 05:03 AM
Authorized User
 
Join Date: Jul 2003
Location: Davao, , Philippines.
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
Reply With Quote
  #6 (permalink)  
Old March 23rd, 2005, 09:55 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
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
Reply With Quote
  #7 (permalink)  
Old March 28th, 2005, 01:02 AM
Authorized User
 
Join Date: Jul 2003
Location: Davao, , Philippines.
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
Reply With Quote
  #8 (permalink)  
Old March 28th, 2005, 09:43 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 02:23 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.