Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Treeview - Hiding Horizontal Scrollbar

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Media.Imaging 1 23
Video Player 12 27
VS2013 publish C# application Created folder -- where is it??? 10 27
need to convert function to c# 5 23
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

789 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