Solved

Treeview - Hiding Horizontal Scrollbar

Posted on 2006-07-13
5
2,041 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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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 …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

809 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