0

Say I have a ListBox control having ID myList, to which I've added 50 items. The vertical scrollbar is inevitably displayed on the right-side of the control. Two related questions:

  1. How do I determine at runtime what value to set myList.Height to so that the scrollbar will NOT be displayed?

  2. How do I determine the height that one row requires (with padding)?

The value of myList.ClientSize.Height changes if the font is changed (for internationalisation), so this needs to be dynamic when the form loads.

Note: If you are wondering "Why remove the scrollbar?", I intend to handle scrolling separately by placing the ListBox on a parent control and modifying myList.Top in response to clicks on Up/Down Buttons.

AlainD
  • 5,413
  • 6
  • 45
  • 99

1 Answers1

0

Try this C# ListView Disable Horizontal Scrollbar

For compact framework this has to be changed to

[DllImport ("coredll")]
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);
}
private void HideScrollBars ()
{
    ShowScrollBar(listView1.Handle.ToInt64(), SB_BOTH, 0);
}

There is another solution at How to hide the vertical scroll bar in a .NET ListView Control in Details mode, again: replace user32 by coredll for compact framework/Windows Mobile 6.x

josef
  • 5,951
  • 1
  • 13
  • 24
  • Unfortunately this does not work as `coredll.dll` does not export the `ShowScrollbar` method. In managed applications which make some use of `P/Invoke` it is sensible to call `Marshal.PrelinkAll(this.GetType());` early in the application life to confirm all `P/Invoke` methods are available. My application immediately throws an exception for `ShowScrollbar`. – AlainD Sep 12 '17 at 09:20
  • A nice workaround, suggested in this article: https://www.pcreview.co.uk/threads/hiding-vertical-scrollbar-in-listbox.2890942/, is to simply limit the number of items in the ListBox or ListView so that no scrollbar is required. You then just change a page number and update the view to scroll up or down. – AlainD Sep 12 '17 at 12:18
  • 1
    -1 for showing answer that uses API that is not available on Windows CE: ShowScrollBar is not supported on Windows CE 5 based OS. – josef Sep 12 '17 at 17:33
  • You may write a custom control that behaves like a list box: see here https://www.codeproject.com/Articles/24048/Implementing-a-smoothly-animated-ListBox – josef Sep 12 '17 at 17:40
  • I'm confused. Your answer uses `ShowScrollBar` which is not available on CE 5.0 and 6.0. Then you comment to say "-1 for showing answer that uses API that is not available on Windows CE"...about your own answer. What am I missing? – AlainD Sep 13 '17 at 20:06