Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

715 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