0

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.

enter image description here

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

Community
  • 1
  • 1
Vikneshwar
  • 1,029
  • 4
  • 20
  • 38
  • It looks like [XY problem](http://meta.stackexchange.com/q/66377). Are you trying to disable horizontal scrollbar, because you set column header too long? – Sinatr Apr 30 '14 at 12:39
  • @Sinatr I tried changing the Column Header many times but still was facing the issue so only i posted over here. – Vikneshwar Apr 30 '14 at 13:45
  • Try to use [auto-size](http://stackoverflow.com/q/1257500/1997232) column width. – Sinatr Apr 30 '14 at 13:56

1 Answers1

-1

After much of Googling and little hint from Sinatr I finally came up with the solution. And of course as the comment states I was in a XY Problem. So this is what I did.

  • I first changed the Scrollable property of the ListView to true.
  • Removed the Chunk of codes that I mentioned above in my question.

And here is the extra lines of code that I added just after the ListView

lv.Items.Clear();
foreach (string newval in stringlist)
    lv.Items.Add(newval);
lv.Columns[0].AutoResize(ColumnHeaderAutoResizeStyle.None);
lv.Columns[0].Width = 'Your own size';
lv.Columns[0].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);

Doing which I achieved the following things

  • Disabled Horizontal ScrollBar
  • Navigation Using Up-Down arrows
  • The vertical ScrollBar doesnot appear unwantedly.
Community
  • 1
  • 1
Vikneshwar
  • 1,029
  • 4
  • 20
  • 38