Completed
Last Updated: 28 Sep 2018 08:44 by Dimitar
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 11 Sep 2018 10:00
Category:
Type: Bug Report
1
FIX. RadListView - searching with text starting with similar letters doesn't navigate you to the correct item
To reproduce: add a RadListView with several items that start with "a". One of the items should start with "aa". Enable the keyboard navigation. If you type "aa" fast so that it is within the specified KeyboardSearchResetInterval, the user should be navigated to the item that starts with "a". 

        Dim dt As New DataTable
        dt.Columns.Add("Column1")
        dt.Columns.Add("Column2")
        dt.Columns.Add("Column3")
        Dim dr1 As DataRow = dt.NewRow
        Dim dr2 As DataRow = dt.NewRow
        Dim dr3 As DataRow = dt.NewRow
        Dim dr4 As DataRow = dt.NewRow
        Dim dr5 As DataRow = dt.NewRow
        dr1.ItemArray = {"aaron", "Waters", "Florida"}
        dt.Rows.Add(dr1)
        dr2.ItemArray = {"Andrew", "Smith", "Ohio"}
        dt.Rows.Add(dr2)
        dr3.ItemArray = {"Art", "Graves", "Michigan"}
        dt.Rows.Add(dr3)
        dr4.ItemArray = {"Bridgette", "Patterson", "Colorado"}
        dt.Rows.Add(dr4)
        dr5.ItemArray = {"Amanda", "Patterson", "Colorado"}
        dt.Rows.Add(dr5)
        LV_Contacts.DataSource = dt
        LV_Contacts.DisplayMember = "Column1"

        Me.LV_Contacts.KeyboardSearchEnabled = True
        Me.LV_Contacts.KeyboardSearchResetInterval = 2000

Workaround:

   Public Class MyListView
        Inherits RadListView
        Protected Overrides Function CreateListViewElement() As RadListViewElement
            Return New MyRadListViewElement()
        End Function
        Public Overrides Property ThemeClassName As String
            Get
                Return GetType(RadListView).FullName
            End Get
            Set(value As String)
                MyBase.ThemeClassName = value
            End Set
        End Property
    End Class

    Public Class MyRadListViewElement
        Inherits RadListViewElement

        Protected Overrides Function CreateViewElement() As BaseListViewElement
            If Me.ViewType = ListViewType.DetailsView Then
                Return New CustomDetailListViewElement(Me)
            End If

            Return MyBase.CreateViewElement()
        End Function
        Protected Overrides ReadOnly Property ThemeEffectiveType() As Type
            Get
                Return GetType(RadListViewElement)
            End Get
        End Property
    End Class


    Public Class CustomDetailListViewElement
        Inherits DetailListViewElement
        Public Sub New(owner As RadListViewElement)
            MyBase.New(owner)

        End Sub
        Protected Overrides ReadOnly Property ThemeEffectiveType() As Type
            Get
                Return GetType(DetailListViewElement)
            End Get
        End Property

        Dim searchBuffer As StringBuilder
        Protected Overrides Sub HandleNavigation(keyChar As Char)
            If Not Me.Owner.KeyboardSearchEnabled Then
                Return
            End If

            Dim fi As FieldInfo = GetType(BaseListViewElement).GetField("typingTimer", BindingFlags.Instance Or BindingFlags.NonPublic)
            Dim typingTimer As Timer = TryCast(fi.GetValue(Me), Timer)
            If typingTimer.Enabled Then
                typingTimer.[Stop]()
                typingTimer.Start()
            Else
                searchBuffer = New StringBuilder()
                typingTimer.Start()
            End If

            searchBuffer.Append(keyChar)
            Dim searchCriteria As String = searchBuffer.ToString()
            Dim itemToSelect As ListViewDataItem = GetFirstMatch(searchCriteria)

            If itemToSelect IsNot Nothing Then
                Me.ProcessSelection(itemToSelect, Keys.None, False)
            End If
        End Sub
    End Class
0 comments