Link to home
Start Free TrialLog in
Avatar of collages
collagesFlag for United States of America

asked on

Treeview - Hiding Horizontal Scrollbar

I have a treeview which nodes are added and deleted every so often and the horizontal position of scroll bar changes.

Is there a way i can fix the horizontal scrollbar to one position
 - or -
Get rid of it entirely?  

Either one of these solutions would be acceptable.
Avatar of vo1d
vo1d
Flag of Germany image

do you use beginupdate() endupdate method before and after your add cycle?
Avatar of collages

ASKER

Yes i do.
ASKER CERTIFIED SOLUTION
Avatar of vo1d
vo1d
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
here is a tree which works. you will just have to implement the flag i mentioned:

public class CustomTreeView : TreeView
        {
            private const int WM_NCCALCSIZE = 0x0083;
            private const int SB_HORZ       = 0;
            private const int SB_VERT       = 1;
            private const int SB_CTL        = 2;
            private const int SB_BOTH       = 3;
       
            [DllImport("user32.dll")]
            private static extern int ShowScrollBar(IntPtr hWnd, int wBar, int bShow);
           
            public CustomTreeView() : base()
            {
           
            }
           
            protected override void WndProc(ref Message m)
            {
                switch(m.Msg)
                {
                    case WM_NCCALCSIZE:
                        ShowScrollBar(base.Handle, SB_BOTH, 0);
                        break;
                }
                base.WndProc(ref m);
            }            
        }
Perfect.