Windows Develop Bookmark and Share   
 index > Windows Forms General > get rid of the treeview horizontal scrollbar
 

get rid of the treeview horizontal scrollbar

the horizontal scrollbar is always there in the treeview box. how can I hide it?

thanks for any tips!

Cyrus Chan  Friday, July 28, 2006 3:39 PM

Cyrus,
it depends on the version.
Both in 2003 and 2005, you always get an horizontal (or vertical) scrollbar if your content exceeds the width of the control. You can eliminate the behaviour by setting the Scrollable property to false, but this will make both the horizontal and vertical scrollbar disappear, which might not be what you want.

In Visual Studio 2003, there was a strange bug, that would make the horizontal scroll bar appear (and without the visual styles..) regardless of what was shown on the screen. The problem usually goes away if you resize the treeview, as this apparently forces the control to reevaluate the need of the scroll bar.
The hack is obvious (and ugly), but works:

In your Form_Load:
...
int size = treeView1.Width;
treeView1.Width = 0;
Application.DoEvents ();
treeView1.Width = size;
...

HTH
--mc

Mario Cossi  Friday, July 28, 2006 7:06 PM
Dear MC,

Thanks a lot for your reply... I also found other solutions on the web after inputting the right key word on Google. Most of the solutions are to add the tree nodes in Form_Load() and the horizontal scroll bar will disappear. And it works for me.

However, I experienced another problem. After the tree has been built, I expandAll() and display the checkbox in each node, and then I collapseAll()...... God... the horizontal scrollbar shows up again......

any idea?
Cyrus Chan  Saturday, July 29, 2006 3:30 AM
Further findings....

in my VS2003

the following code just works.... and you can put them anywhere you want to make the H scroll bar disappear.


int size = this.treeView1.Width;
this.treeView1.Width = 0;
this.treeView1.Width = size;
Cyrus Chan  Saturday, July 29, 2006 3:42 AM

You can use google to search for other answers

Custom Search

More Threads

• Controlling WebBrowser Popup window inside application
• Querry in using tab control paint event
• Printing in csharp
• Pointers in VB
• Can I run an installed win app from another machine?
• Exposing events of a nested control
• Windows Forms designer moves my controls on build
• The biggest thing I'd like is...
• avoid object to dispose
• how to get windows form template working?