Solved

treeview node search

Posted on 2001-09-06
4
319 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
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 100 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

786 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