Solved

VB6 TreeView Nodes limit problem

Posted on 2004-04-09
6
2,218 Views
Last Modified: 2013-12-26
Hi,

I have a VB6 TreeView control in my VB6 application, and I need to load a lot of data into the tree, say 50,000 nodes.  The treeview was able to load all 50,000 nodes all right - although very slow - and the nodes show up in the tree.  The problem is, when I iterate through the nodes like this:

Dim Nodes As MSComctlLib.Nodes, curNode As MSComctlLib.Node
Dim i As Long

Set Nodes = MyTree.Nodes
For i = 1 To Nodes.count
      Set curNode = Nodes.Item(i)
      If curNode.children > 0 Then
           ' Do some thing with the node
      End If
Next

The Nodes.count will be a negative -27536 when actually there are 50,000 node in the treeview.  It seems like there is a limit to Nodes.count that you cannot exceed, and the iteration in the code above won't work.

Do anyone has a solution to my problem?

Thanks for your help.
0
Comment
Question by:jayleno
  • 3
  • 3
6 Comments
 
LVL 27

Accepted Solution

by:
Dabas earned 250 total points
ID: 10796349
Hi jayleno:
Bugger!
If you look up Nodes.Count in Object Browser, you will see that it is defined as Integer!
This explains your problem, but does not provide the solution.

I would suggest you iterate through the tree using Node.Next instead of using the For loop.

Something like

Dim curNode as Node
Set curNode = MyTree.Nodes.Item(1) 'First node
While not curNode is Nothing
    If curNode.Children > 0 then
        'Do something
    End If
    Set curNode = curNode.Next
Wend

Dabas
0
 

Author Comment

by:jayleno
ID: 10805911
Thanks Dabas!  It works.
0
 

Author Comment

by:jayleno
ID: 10816347
Hi Dabas,

A few more words.  Using Node.Next to iterate through the tree works, but it's still a much easier and cleaner iteration using the For loop and Nodes.count.  Because depending on the tree structure, it can be a lot more work to iterate through every node in the tree using Node.Next.  Sure hope the Nodes.count can be something bigger than a integer!
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 27

Expert Comment

by:Dabas
ID: 10816431
jayleno:
You might have a point, but I will have to disagree with part of it:
1) The documentation describes Nodes.count as an integer, which as you point out is stupid. Silly M$! I just checked in VB.NET, and there Nodes.Count ALSO is an integer... only in .NET and integer is the same as a long in VB6

2) Easier and cleaner?
One says
For i = 1 to TreeView1.Nodes.Count -1

Next

While not curNode is Nothing
      If....

      Else
Wend

So there is an extra IF there.... I do not think that it makes the iteration that much easier either, and it overcomes the Integer limitation!

Dabas
0
 

Author Comment

by:jayleno
ID: 10816543
Dabas,

No, what I meant by "depending on the tree structure, it can be a lot more work to iterate through every node in the tree using Node.Next" is, the tree can have multiple levels, and when one just does Set curNode = curNode.Next you are only iterating through one level of the tree.  Of course you want to go through all top level node, the node on the next level, ..., until you get to the bottom level.  It does't have to be in that order, but you have to manage to traverse all the nodes in the tree, not just some, and using the indexes by using Nodes.Count makes it easier.  Using Set curNode = curNode.Next you have to go through all parents and children.  It can be done, just more work.  But you get my drift.
0
 
LVL 27

Expert Comment

by:Dabas
ID: 10818461
jayleno,
Your original code also seems to handle children separately.
If you really have to traverse through all nodes, and not just one level, then recursion is very effective...
It might also solve your integer problem, if the amount of nodes at a particular level do not cross the integer boundary

Dabas
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

808 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