Solved

Treeview - Hiding Horizontal Scrollbar

Posted on 2006-07-13
5
2,035 Views
Last Modified: 2008-03-03
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.
0
Comment
Question by:collages
  • 3
  • 2
5 Comments
 
LVL 11

Expert Comment

by:vo1d
ID: 17101861
do you use beginupdate() endupdate method before and after your add cycle?
0
 
LVL 1

Author Comment

by:collages
ID: 17102893
Yes i do.
0
 
LVL 11

Accepted Solution

by:
vo1d earned 500 total points
ID: 17103504
ok, then you can disable the scrollbar by using the win32 api function  ShowScrollBar.

derive from treeview and implement this:

// Win32 Constants
private const int SB_HORZ = 0;
private const int SB_VERT = 1;
private const int SB_CTL  = 2;
private const int SB_BOTH = 3;

// Win32 Functions
[DllImport("user32.dll")]
private static extern int ShowScrollBar(IntPtr hWnd, int wBar, int bShow);

protected override void WndProc(ref Message m)
{
    switch(m.Msg)
    {
        //
        // ...
        //

        case WM_NCCALCSIZE:
            ShowScrollBar(m.HWnd, SB_CTL, 0);
            break;
    }

    base.WndProc(ref m);
}

if you are adding your nodes, set a flag which indicates it.
then in WM_NCCALCSIZE, check for that flag, if true, make
ShowScrollBar(m.HWnd, SB_CTL, 0);
otherwise,
ShowScrollBar(m.HWnd, SB_CTL, 1);

0
 
LVL 11

Expert Comment

by:vo1d
ID: 17103604
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);
            }            
        }
0
 
LVL 1

Author Comment

by:collages
ID: 17109690
Perfect.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

864 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now