RadListView detail mode, page up/down keys

1 Answer 81 Views
ListView
darin
Top achievements
Rank 1
Iron
Iron
darin asked on 25 Mar 2022, 01:55 PM

I have a radlistview setup for viewtype=DetailsView. The HOME/END keys work, but the Page up/down only move the scroll area, not the selected item.

You will notice when running the below code, page up/down will always keep the selected item as FIELD 0 (the top one), but END moves the select to the last entry, and HOME moves the select to the first entry.

How can i get the page up/down to move the selected item. I am probably just missing something really simple that i can't seem to find.

        ListViewDetailColumn1.HeaderText = "Column 0"
        ListViewDetailColumn1.Width = 100.0!
        ListViewDetailColumn2.HeaderText = "Column 1"
        ListViewDetailColumn2.Width = 100.0!
        Me.RadListView1.Columns.AddRange(New Telerik.WinControls.UI.ListViewDetailColumn() {ListViewDetailColumn1, ListViewDetailColumn2})
        Me.RadListView1.ItemSpacing = -1
        Me.RadListView1.KeyboardSearchEnabled = True
        Me.RadListView1.Location = New System.Drawing.Point(200, 72)
        Me.RadListView1.Name = "RadListView1"
        Me.RadListView1.Size = New System.Drawing.Size(296, 208)
        Me.RadListView1.TabIndex = 2
        Me.RadListView1.ViewType = Telerik.WinControls.UI.ListViewType.DetailsView

 Private Sub RadListView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadListView1.DoubleClick
        MsgBox("DoubleClick" & vbCrLf & RadListView1.SelectedItem(0).ToString)
    End Sub

    Private Sub RadListView1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles RadListView1.KeyPress
        If e.KeyChar = ChrW(13) Then
            MsgBox("KeyPress" & vbCrLf & RadListView1.SelectedItem(0).ToString)
        End If
    End Sub

    Private Sub LoadList()
        Dim lItem As Telerik.WinControls.UI.ListViewDataItem
        Dim cnt As Integer
        Dim selected As Boolean = False
        For cnt = 0 To 100 Step 1
            lItem = New Telerik.WinControls.UI.ListViewDataItem
            lItem.SubItems.Add(CStr(cnt))
            lItem.SubItems.Add("FIELD " & CStr(cnt))
            RadListView1.Items.Add(lItem)
            If Not selected Then
                RadListView1.SelectLastAddedItem = False
                selected = True
            End If
        Next
    End Sub

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 28 Mar 2022, 07:00 AM
Hello, Darin,

Usually, pressing the PageDown/PageUp keys are expected to move the scrollbar. If you want to move the selected item, feel free to use the up/down arrow keys. 

However, I have prepared a sample custom implementation of RadListView that handles the PageDown/PageUp in a similar way like the Up/Down arrows:
    Public Class CustomListView
    Inherits RadListView
        Protected Overrides Function CreateListViewElement() As RadListViewElement
            Return New CustomListViewElement()
        End Function
        Public Overrides Property ThemeClassName As String
            Get
                Return GetType(RadListViewElement).FullName
            End Get
            Set(value As String)
                MyBase.ThemeClassName = value
            End Set
        End Property
    End Class

    Public Class CustomListViewElement
    Inherits RadListViewElement

        Public Overrides Function ProcessKeyDown(e As KeyEventArgs) As Boolean
            If e.KeyData = Keys.PageDown Then
                Return MyBase.ProcessKeyDown(New KeyEventArgs(Keys.Down))
            ElseIf e.KeyData = Keys.PageUp Then
                Return MyBase.ProcessKeyDown(New KeyEventArgs(Keys.Up))
            End If

            Return MyBase.ProcessKeyDown(e)
        End Function

        Protected Overrides ReadOnly Property ThemeEffectiveType() As Type
            Get
                Return GetType(RadListViewElement)
            End Get
        End Property
    End Class

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

darin
Top achievements
Rank 1
Iron
Iron
commented on 28 Mar 2022, 10:57 AM

I think there might be a miss understanding. I do want the page up/page down to move the scroll bar, but it moves the scroll bar because the selected item has moved down 10 lines. So the page up/page down is moving the selected item, which in-turn moves the scroll bar, not that the page up/page down ONLY moves the scroll bar.
Dess | Tech Support Engineer, Principal
Telerik team
commented on 28 Mar 2022, 11:42 AM

Hello, Darin,

By default, the PageDown/PageUp keys move only the vertical scrollbar without managing the SelectedItem at all. If you need to manage the SelectedItem as well, the previously suggested code snippet demonstrates how to move the SelectedItem with delta=1. In case you need to move with 10 items at once, you can adjust the code as follows: 
        Public Overrides Function ProcessKeyDown(e As KeyEventArgs) As Boolean
            If e.KeyData = Keys.PageDown Then
                For index = 1 To 10
                    MyBase.ProcessKeyDown(New KeyEventArgs(Keys.Down))
                Next

                Return True
            ElseIf e.KeyData = Keys.PageUp Then

                For index = 1 To 10
                    MyBase.ProcessKeyDown(New KeyEventArgs(Keys.Up))
                Next
                Return True
            End If

            Return MyBase.ProcessKeyDown(e)
        End Function

        Protected Overrides ReadOnly Property ThemeEffectiveType() As Type
            Get
                Return GetType(RadListViewElement)
            End Get
        End Property
    End Class
darin
Top achievements
Rank 1
Iron
Iron
commented on 28 Mar 2022, 11:51 AM

Is this behavior because i am using the RADListView and i should be using something else? I have not seen software where the page up/page down does not also move the cursor up and down.
Dess | Tech Support Engineer, Principal
Telerik team
commented on 29 Mar 2022, 07:13 AM

Hi, Darin,

I would say that the appropriate control for your scenario is RadGridView, not RadListView.  The PageUp/PageDown keys move the current row up/down with a step controlled by the visible grid area. Otherwise, feel free to use the above suggested solution for RadListView.

 

darin
Top achievements
Rank 1
Iron
Iron
commented on 30 Mar 2022, 11:18 AM

It would be awesome as a suggestion to get the page up/page down to also move the selected item like other programs and the datagridview.
Dess | Tech Support Engineer, Principal
Telerik team
commented on 31 Mar 2022, 12:32 PM

Darin, please have in mind that changing a behavior in RadListView that has been existing for years would be a massive change for all the existing applications of our customers out there. That is why we take very seriously any changes that would affect a great number of customers and applications. If we have similar requests from other customers, we will definitely consider them in the future improvement of the control. 
Tags
ListView
Asked by
darin
Top achievements
Rank 1
Iron
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or