Solved

Treeview - Hiding Horizontal Scrollbar

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

757 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

19 Experts available now in Live!

Get 1:1 Help Now