Solved

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

Posted on 2006-11-09
4
901 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
[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
  • 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to remove error in database 6 56
Create simple VB.net Add-in for Excel in Office 365 2 61
FTP recursive download files 5 28
Select coumns form Data table? 3 27
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

752 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