C # ListView Disable horizontal scrollbar

Is there a way to stop the horizontal scrollbar ever appearing in the list? I want the vertical scroll bar to be displayed as needed, but I want the horizontal scroll bar to never be displayed.

I would suggest that this has something to do with WndProc?

thanks

+7
source share
4 answers

You can try something like this, I used it once in the project and worked:

[DllImport ("user32")] private static extern long ShowScrollBar (long hwnd , long wBar, long bShow); long SB_HORZ = 0; long SB_VERT = 1; long SB_BOTH = 3; private void HideHorizontalScrollBar () { ShowScrollBar(listView1.Handle.ToInt64(), SB_HORZ, 0); } 

Hope this helps.

+4
source

There is a much simpler way to eliminate the bottom scroll bar and display vertically. It consists in making sure that the title and if there is no title, the rows are the width of listview.Width - 4 , and if the vertical scroll bar is displayed, then listview.Width - Scrollbar.Width - 4;

The following code demonstrates how:

 lv.Columns[0].Width = Width - 4 - SystemInformation.VerticalScrollBarWidth; 
+6
source

@bennyyboi's answer is unsafe, as it will unbalance the stack. instead of DllImport you should use the following code:

 [System.Runtime.InteropServices.DllImport("user32", CallingConvention=System.Runtime.InteropServices.CallingConvention.Winapi)] [return: System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)] private static extern bool ShowScrollBar(IntPtr hwnd, int wBar, [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)] bool bShow); 

Andreas Reiff describes this in his comment above, looking again, so I think everything is nicely formatted here.

+4
source

The best solution is the accepted answer, which was given here: How to hide the vertical scrollbar in the .NET ListView control in the details mode

It works great, and you don't need some tricks, such as adjusting the column width. In addition, you turn off the scroll bar immediately when creating the control.

The downside is that you have to create your own list view class, which has a System.Windows.Forms.ListView value to override WndProc . But that is the way.

To disable the horizontal scrollbar, be sure to use WS_HSCROLL instead of WS_VSCROLL (which was used in the linked answer). The value of WS_HSCROLL is 0x00100000 .

+1
source

All Articles