Most VB controls don’t let you determine whether they should display a scrollbar or not. For example, a VB ListBox control displays a vertical scrollbar only when the number of its items is larger than the number of visible items. If you want to directly control individual scrollbars, you can use the following two API functions:
Private Declare Function ShowScrollBar Lib "user32" (ByVal hwnd As Long, _ ByVal wBar As Long, ByVal bShow As Long) As LongPrivate Const SB_HORZ = 0Private Const SB_VERT = 1Private Const SB_BOTH = 3
For example, you can display the vertical scrollbar of a ListBox control, even if the ListBox doesn’t contain any item, using this code:
ShowScrollBar List1.hWnd, SB_VERT, True
This trick works with several other controls, e.g. ComboBox and TreeView controls, but not all. For example, while you can add a scrollbar to a ListView control, as soon as VB redraws the control (for example, after adding an item), the original settings are restored.