Visual Basic Reference

Scroll Event

See Also    Example    Applies To

Occurs when the scroll box on a ScrollBar control, or an object which contains a scrollbar, is repositioned or scrolled horizontally or vertically.

Syntax

Private Sub DataGrid_Scroll([cancel As Integer])

Private Sub object_Scroll( )

The Scroll event syntax has these parts:

Part Description
object An object expression that evaluates to an object in the Applies To list.
cancel Determines whether the scroll operation succeeds and the ScrollBar or DataGrid are repainted, as described in Remarks.

Remarks

For a DataGrid control, this event occurs when the user scrolls the grid horizontally or vertically but before the grid is repainted to display the results of the scroll operation.

For a ComboBox control, this event occurs only when the scrollbars in the dropdown portion of the control are manipulated.

Setting cancel to True causes the DataGrid scroll operation to fail, and no repaint operation occurs. If the Refresh method is invoked within this event, the grid is repainted in its new (scrolled) arrangement even if cancel is set to True. However, in this case, the grid is repainted again because the scroll operation fails and it snaps back to its previous position.

You can use this event to perform calculations or to manipulate controls that must be coordinated with ongoing changes in scroll bars. In contrast, use the Change event when you want an update to occur only once, after a ScrollBar control changes.

Note   Avoid using a MsgBox statement or function in this event.