Some events not processed by RadListViewElement when inside a custom RadControl

1 Answer 95 Views
General Discussions ListView
ASM
Top achievements
Rank 1
Iron
Iron
ASM asked on 29 Apr 2021, 12:37 PM | edited on 29 Apr 2021, 08:36 PM

 

Hello,

I'm struggling to get some events to work on a RadListViewElement, which is a child of a custom RadElement, which in turn is inside another custom RadControl. I guess a few lines of code will help to describe this:

Imports Telerik.WinControls
Imports Telerik.WinControls.UI

Public Class xElement
    Inherits RadElement

    Private listElement As RadListViewElement

    Public Sub New()
        'Me.NotifyParentOnMouseInput = True
        'Me.ShouldHandleMouseInput = True
        'Me.Capture = True
        'Me.CaptureOnMouseDown = True
    End Sub

    Protected Overrides Sub OnLoaded()
        MyBase.OnLoaded()

        AddHandler listElement.ItemMouseUp, Sub(s, e)
                                                If e.OriginalEventArgs.Button = MouseButtons.Left Then
                                                    listElement.SelectedItem = e.Item
                                                End If
                                            End Sub
    End Sub

    Protected Overrides Sub CreateChildElements()
        MyBase.CreateChildElements()

        listElement = New RadListViewElement
        With listElement
            '.ShouldHandleMouseInput = True
            '.NotifyParentOnMouseInput = True
            '.Capture = True
            '.CaptureOnMouseDown = True
            .ViewType = ListViewType.ListView 
            .DataSource = New List(Of String)(New String() {"a", "b", "c"})
        End With
        Me.Children.Add(listElement)
    End Sub

End Class
Imports Telerik.WinControls

<ToolboxItem(True)>
Public Class xControl
    Inherits RadControl

    Private element As xElement

    Public Sub New()
        element = New xElement()
        RootElement.Children.Add(element)
    End Sub

End Class

Some remarks on this piece of code:
- The items in listview react to events like mouseEnter/Leave.
- These items can't be selected by using the mouse, the click event does nothing on them, the action needs to be managed manually, which here is done in the OnLoaded() sub.
- The click event works on other elements inside listView, so, for instance, the scrollbar of the item container can be clicked, the list of items can be scrolled.

So, some events work out-of-the-box and some do not, and a certain event works here but not there, so I'm somewhat confused on what's going on. Anyway, it doesn't seem like the way it's supposed to be, and I'm sure the proper solution is a lot less cumbersome than manually capturing each event and then replicating the original behavior.

I guess I'm just missing something about how TPF works, maybe there's some element not initialized correctly, perhaps I need to enable some property. Any suggestions on this?

Thank you

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 30 Apr 2021, 07:01 AM
Hello, Armand, 

The provided code snippet is greatly appreciated. I used it in my sample project to test the behavior on my end. I confirm that that when using the custom implementation, the items in RadListViewElement don't get selected after clicking.

Usually, the RadListView control handles the MouseUp message and invokes the RadListViewElement.ProcessMouseUp method which internally processes the selection. Since there is no RadListView control in this implementation, the RadListViewElement.ProcessMouseUp method is not triggered.

The possible solution that I can suggest is to use a RadHostItem and host the entire RadListView control:
    <ToolboxItem(True)>
    Public Class xControl
        Inherits RadControl

        Private element As xElement

        Public Sub New()
            element = New xElement()
            RootElement.Children.Add(element)
        End Sub

    End Class

    Public Class xElement
        Inherits RadElement

        Private listView As RadListView

        Public Sub New() 
        End Sub
 

        Protected Overrides Sub CreateChildElements()
            MyBase.CreateChildElements()

            listView = New RadListView
            Dim host As New RadHostItem(listView)
            With listView
               
                .ViewType = ListViewType.ListView
                .DataSource = New List(Of String)(New String() {"a", "b", "c"})
            End With
            Me.Children.Add(host)
        End Sub

    End Class
The attached gif file illustrates the achieved result.

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

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Тhe web is about to get a bit better! 

The Progress Hack-For-Good Challenge has started. Learn how to enter and make the web a worthier place: https://progress-worthyweb.devpost.com.

Tags
General Discussions ListView
Asked by
ASM
Top achievements
Rank 1
Iron
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or