Solved

treeview node search

Posted on 2001-09-06
4
317 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
  • 2
4 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
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
Comment Utility
ping
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 100 total points
Comment Utility
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
Comment Utility
thanks worked great
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now