Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2006-11-09
4
Medium Priority
?
939 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 200 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

963 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