TreeView control partially hiding last node in VB.Net Visual Studio 2005

Posted on 2006-11-09
Last Modified: 2008-01-16
I can't figure out why the treeview control in a VB.Net app is behaving like this.  I can create the behavior as follows:  1) Create a new project -> windows app
2) Add a treeview to the form and place the following code in the form load event handler to fill the treeview with 100 nodes:

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        For i As Integer = 1 To 100
        Next i
    End Sub

When I run the program from with VS it hides part of the last node when I scroll down to the bottom of the treeview.  Am I missing something or is this a bug with the control in .NET?  I can get it to hide almost all of the last node by changing the height of the control.  I keep thinking that I'm just overlooking something simple, but can't figure it out.  Please help me to salvage my sanity.
Question by:choelt
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
  • 2
LVL 10

Expert Comment

ID: 17908626
Seems ok to me, I'm on vs2005 though ??

Author Comment

ID: 17908788
I'm using vs2005 as well.  I was able to get it to behave correctly by adding 2 lines as follows:

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        For i As Integer = 1 To 100
        Next i
       TreeView1.Scrollable = False
       TreeView1.Scrollable = True
    End Sub

Is your treeview control version ?
LVL 34

Accepted Solution

Sancler earned 50 total points
ID: 17910975
I don't think you're missing anything simple.  I reckon it's a bug.

My guess is that it results from the scrolling mechanism failing to count the additions properly.  

If you think about the separate scrollbars (on which I imagine the ones integral to the TreeView must be based) they work with a Maximum and a Value.  When you want to show a number of items you have to reduce the Maximum by the number of items that can be displayed at one time.  If you get that calculation wrong, you get a similar effect.  The TreeView has a .VisibleCount property, which appears to be right in your example code: that is "the number of items that can be displayed at one time".  So I reckon the (internal) .Maximum for the integral scrollbar must be wrong.

When you add

       TreeView1.Scrollable = False
       TreeView1.Scrollable = True

my guess is that the False setting drops the .Maximum in the internal scrollbar workings and the True setting makes it re-calculate it.  But this time, as it is doing it by actually referring to the number of nodes, rather than by incrementing, it gets it right.  I've found a similar correcting effect with setting the TreeView's .Visible to False at design time and then setting it to True after all the nodes are loaded.

It's difficult to test my hypothesis.  But it's consistent with the behaviour you describe (and I've been able to reproduce in my tests).

I think you've found the best (or certainly an adequate) workaround.


Author Comment

ID: 17911277
I agree that it is more than likely a bug and thanks for your in depth analysis.  I'm one of those that have to understand why.

Featured Post

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

623 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