Solved

VB6 TreeView Nodes limit problem

Posted on 2004-04-09
6
2,244 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
[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
  • 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
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!

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

733 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