Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

treeview node search

Posted on 2001-09-06
4
Medium Priority
?
338 Views
Last Modified: 2011-10-03
I need a function to get a treeview's node's children's indexes.  ex what ever node I have highlighted in a treeview, i need to be able to check mark all nodes under it and their children and theirs etc. the treeview is a MS treeview with the checkbox property set to true.  any function will do, vbonly or api. Thanks in advance
0
Comment
Question by:jrspano
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6462466
Using VB (I would think that there would have to be a faster way using API) this seems to work for me, but you may need to double check me.

Private Sub TreeView1_NodeCheck(ByVal Node As MSComctlLib.Node)
 
CheckNodes Node, Node.Checked

End Sub

Sub CheckNodes(ByVal Node As MSComctlLib.Node, ByVal Check As Boolean)
Dim I As Integer
Dim nodChild As Node

If Node.Children Then
   Set nodChild = Node.Child
End If
For I = 1 To Node.Children
   nodChild.Checked = Check
   CheckNodes nodChild, Check
   Set nodChild = nodChild.Next
Next

End Sub
0
 
LVL 3

Expert Comment

by:adg
ID: 6462521
ping
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 400 total points
ID: 6462845
The following code may be a bit more efficient:

Private Sub TreeView1_NodeCheck(ByVal Node As MSComctlLib.Node)

If Node.Children Then
   CheckNodes Node, Node.Checked
End If

End Sub

Sub CheckNodes(ByVal Node As MSComctlLib.Node, ByVal Check As Boolean)
Dim I As Integer
Dim nodChild As Node
Dim intChildren as Integer

Set nodChild = Node.Child
intChildren = Node.Children
For I = 1 To intChildren
  nodChild.Checked = Check
  If nodChild.Children Then
     CheckNodes nodChild, Check
  End If
  If I < intChildren Then  'The last one will not have a next sibling
     Set nodChild = nodChild.Next
  End If
Next

Set nodChild = Nothing

End Sub

You should also note there is a bug with the NodeCheck event.  Here is the MSDN article that describes a workaround:
BUG: TreeView: NodeCheck Event Does Not Occur (Q221557)
0
 
LVL 3

Author Comment

by:jrspano
ID: 6464308
thanks worked great
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

664 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question