Solved

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

Posted on 2006-11-09
4
850 Views
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
            TreeView1.Nodes.Add(i.ToString)
        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.
0
Comment
Question by:choelt
  • 2
4 Comments
 
LVL 10

Expert Comment

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

Author Comment

by:choelt
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
            TreeView1.Nodes.Add(i.ToString)
        Next i
       TreeView1.Scrollable = False
       TreeView1.Scrollable = True
    End Sub

Is your treeview control version 2.0.0.0 ?
0
 
LVL 34

Accepted Solution

by:
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.

Roger
0
 

Author Comment

by:choelt
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.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 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

10 Experts available now in Live!

Get 1:1 Help Now