Solved

treeview node search

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel VBA combine two working workbooks 8 46
VBA open file from excel cell 4 36
MS Access Search and Replace Using VBA 6 57
Macro Excel - Multiple If conditions 2 63
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

914 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

14 Experts available now in Live!

Get 1:1 Help Now