Search code examples
c#vb.netwinformstelerikmousewheel

Telerik, Select next page of RadPageView using the mouse wheel?


I have a RadPageView control with pages shown in vertical mode:

enter image description here

I would like to automaticaly select the page above when scrolling up the mouse, and the page below when scrolling the mouse down.

How could be this done?

This is a Pseudocode in VB.Net, but no matter if I can find a solution in C#:

Private Sub RadPageView1_MouseWheel(sender As Object,e As MouseEventArgs) _
Handles RadPageView1.MouseWheel

    Select Case e.Delta

        Case Is > 0 ' MouseWhell scroll up.
            If CurrentPageIndex > 0I Then
                RadPageView1.SelectedPage = ... +1
            End If

        Case Else ' MouseWhell scroll down.
            If CurrentPageIndex < Pages.Count Then
                RadPageView1.SelectedPage = ... -1
            End If

    End Select

End Sub

Solution

  • Done!

    ''' <summary>
    ''' Handles the MouseWheel event of the RadPageView_ActionNames control.
    ''' </summary>
    ''' <param name="sender">The source of the event.</param>
    ''' <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
    Private Sub RadPageView_ActionNames_MouseWheel(sender As Object, e As MouseEventArgs) _
    Handles RadPageView_ActionNames.MouseWheel
    
        Dim ctrl As RadPageView = DirectCast(sender, RadPageView)
        Dim PageIndex As Integer = ctrl.Pages.IndexOf(ctrl.SelectedPage)
    
        Select Case e.Delta
    
            Case Is > 0 ' MouseWhell scroll up.
                If PageIndex > 0I Then
                    ctrl.SelectedPage = ctrl.Pages(PageIndex - 1)
                End If
    
            Case Else ' MouseWhell scroll down.
                If Not PageIndex >= (ctrl.Pages.Count - 1) Then
                    ctrl.SelectedPage = ctrl.Pages(PageIndex + 1)
                End If
    
        End Select
    
    End Sub