In my application I'm using lots of ListView's for many purposes. I want to disable the Horizontal ScrollBar. Which I have done effectively using the following links as references Disable Horizontal ScrollBar 1 , Disable Horizontal ScrollBar 2. The following is my code:
First of all I set the Scrollable Property of the ListView to false
[DllImport("user32.dll")]
static public extern bool ShowScrollBar(System.IntPtr hWnd, int wBar, bool bShow);
private const uint SB_HORZ = 0; //Horrizontal Scroll
private const uint SB_VERT = 1; //Vertical Scroll
private const uint ESB_DISABLE_BOTH = 0x3;
private const uint ESB_ENABLE_BOTH = 0x0;
Created a method so as to use it for all the ListView's throught the application
public void HideHorizontalScrollBar(ListView lv,int value, bool isNeeded)
{
ShowScrollBar(lv.Handle, value, isNeeded);
}
Now referenced this method inside the Contructor of the MainForm just after the InitializeComponent()
private void ListViewHorrizontalScrollBar()
{
//0 for horrizontal
//1 for vertical
_ListViewScrollOperation.HideHorizontalScrollBar(this.lvAntSetExcludedFiles, 0, false);
_ListViewScrollOperation.HideHorizontalScrollBar(this.lvAntSetExcludedFiles, 1, true);
}
Now this thing works perfectly for me. However I just have a small problem. Even if there are Only 2 Values still the Vertical ScrollBar is visible. Even if there isnt any data in the ListView still the Vertical ScrollBar is Visible.
Also I'm not able to navigate from Top-Bottom or from Bottom-Top using the Up and Down arrow keys of the Keyboard since the Scrollable Property of the ListView is set to false. So is there anything else that I can do to tackle with the Issue?
Any help would be really appreciated.
Thanks In Advance