7

I need to have a TreeView with only vertical scrollbar.

I tried this but it doesnt work, the resulting scrollbar doesnt do anything at all.

I tried the opposite (scrollable to true and disable horizontal scrollbar with that user32.dll function) - it doesnt work, when i add long enough stuff to the TreeView the scrollbar shows again...

aleroot
  • 71,077
  • 30
  • 176
  • 213
Istrebitel
  • 2,963
  • 6
  • 34
  • 49

2 Answers2

13

You can try turning on the TVS_NOHSCROLL window style on the treeview control. To do so you have to extend the standard TreeView control with a custom TreeView like this one :

public class NoHScrollTree : TreeView {
protected override CreateParams CreateParams {
get {
    CreateParams cp = base.CreateParams;
    cp.Style |= 0x8000; // TVS_NOHSCROLL
    return cp;
}
} }
aleroot
  • 71,077
  • 30
  • 176
  • 213
  • 1
    Here's a ready-to-go class which has a "HorizontalScrollbar" property that can be set in the designer: https://pastebin.com/dnbGfiqp – Codecat Jun 16 '14 at 13:14
  • It's work fine , But i need horizontal scroll when node text exceed the control. https://ibb.co/ibnCic – Vignesh Nethaji Apr 27 '18 at 11:52
2

If your intention is to get the look and feel like Windows Vista and 7 native tree view, then you should follow this,

How to get Windows native look for the .NET TreeView?

SetWindowTheme is necessary. Then the horizontal scroll bar won't appear.

It works on Windows Vista and Windows 7.

Community
  • 1
  • 1
Lex Li
  • 60,503
  • 9
  • 116
  • 147