HeaderPane
Main
Hide
Share Link
Print

Scrolling

The dropdown portion of a combo box control can be scrolled vertically if it contains more items than it can display and horizontally if its items are wider than the dropdown portion.

Scroll Bars

Scroll bars are defined using window styles when the combo box is created. The window styles WS_VSCROLL and WS_HSCROLL add a vertical and a horizontal scroll bar to the dropdown portion. The combo box window itself never has scroll bars.

A scroll bar is only shown when it is needed and is hidden otherwise. If the window style SFTBOXSTYLE_DISABLENOSCROLL is specified, a scroll bar that is not needed is shown disabled instead of being hidden. SetDisableNoScroll changes this setting after the combo box has been created and GetDisableNoScroll returns the current setting. Scroll bars that are always shown are required for the sizing box of the dropdown portion (see Sizing the Dropdown Portion).

CONTROL "", IDC_BOX, "SftBoxControl60",
        SFTBOXSTYLE_DROPDOWNLIST | WS_VSCROLL | WS_HSCROLL | WS_BORDER | WS_TABSTOP,
        10, 10, 120, 14

Vertical Scrolling

The number of items the dropdown portion of a dropdown combo box or dropdown list combo box displays is defined using SetDroppedHeight. If the combo box contains more items, the remaining items are reached by scrolling.

GetTopIndex returns the index of the item displayed at the top of the dropdown portion and SetTopIndex scrolls the dropdown portion so the specified item is displayed at the top (as far as the end of the list permits). MakeRowVisible scrolls the dropdown portion just enough to make an item visible. If the item is not visible because a parent item is collapsed, both functions first expand its parent items. GetItemsShown returns the number of items that are displayed in the dropdown portion, including a partially displayed item.

The parent window receives the SFTBOXN_TOPCHANGE notification when the item displayed at the top of the dropdown portion has changed.

Horizontal Scrolling

The dropdown portion can be scrolled horizontally if its displayable area (the horizontal scrolling extent) is wider than the dropdown portion and the window style WS_HSCROLL was specified. For performance reasons, the horizontal scrolling extent is not calculated automatically as items are added. The application calls RecalcHorizontalExtent after all items have been added and their attributes have been defined, or sets the extent explicitly using SetHorizontalExtent.

/* add all items, set levels, pictures, column widths, then: */
SftBox_RecalcHorizontalExtent(hwndBox, 0);

If neither RecalcHorizontalExtent nor SetHorizontalExtent is used, horizontal scrolling is not available, even if the window style WS_HSCROLL is specified. As most changes to items and columns can affect the optimal horizontal scrolling extent, RecalcHorizontalExtent should be called again after such changes.

The maximum parameter of RecalcHorizontalExtent can limit the number of items that are analyzed, which shortens the calculation for a combo box with many items. If the last column is not open-ended (see SetOpenEnded), the extent is calculated from the column widths.

GetHorizontalExtent returns the current horizontal scrolling extent in pixels.

GetHorizontalOffset returns the current horizontal scrolling offset in pixels and SetHorizontalOffset scrolls horizontally under program control. MakeColumnVisible scrolls horizontally so the specified column is visible. The static portion of a dropdown list combo box always uses the same horizontal scrolling offset as the dropdown portion, so the columns of both portions remain aligned. The parent window receives the SFTBOXN_OFFSETCHANGE notification when the horizontal scrolling offset has changed.

In a dropdown combo box or dropdown list combo box, horizontal scrolling can often be avoided altogether. If SetDropDownOptimalWidth is used, the dropdown portion is made as wide as the horizontal scrolling extent (as calculated by RecalcHorizontalExtent or defined using SetHorizontalExtent) when it is shown, so it can be wider than the combo box itself.

Smooth Scrolling

When the dropdown portion is scrolled vertically, the items can be scrolled using a smooth scrolling effect. SetUseSmoothScroll enables or disables smooth scrolling. Smooth scrolling is only used if the dropdown portion does not show column headers.

ScrollTips

While the user drags the scroll box of the vertical scroll bar, a ScrollTip can display the text of the item that will be shown at the top of the dropdown portion (see ToolTips).


Last Updated 11/21/2026 - (email)
© 2026 Softel vdm, Inc.