How do I get from RadListView VisualItemFormatting to the actual RadListView.Item being formatted

2 Answers 19 Views
ListView
Curtis
Top achievements
Rank 1
Iron
Iron
Veteran
Curtis asked on 20 Feb 2025, 05:40 AM

Hello everyone :)

I've got a new project that includes a RadListView that I have placed on a WinForm with ViewType = IconsView

I'd like to display a thumbnail along with some HTML text - but I'm struggling getting the data I need from the object being formatted.

Here's my VisualItemFormatting method:

Private Sub rlvScanForms_VisualItemFormatting(sender As Object, e As Telerik.WinControls.UI.ListViewVisualItemEventArgs) Handles rlvScanForms.VisualItemFormatting
Dim myViewElement As RadListViewElement = CType(sender, RadListViewElement)

'               .Item(0) IS WRONG!!!  THiS IS just a place holder for my question to Telerik Forum members :)
If myViewElement.Items(0).Tag IsNot Nothing Then
Dim myScanFormIcon As ScanFormIcon = CType(myViewElement.Items(0).Tag, ScanFormIcon)
Dim myWidth As Integer = myScanFormIcon.IconSize.Width
Dim myHeight As Integer = myScanFormIcon.IconSize.Height
Dim myText As String = myScanFormIcon.DisplayString

If e.VisualItem.Data.Image IsNot Nothing Then
e.VisualItem.Image = e.VisualItem.Data.Image.GetThumbnailImage(myWidth, myHeight, Nothing, IntPtr.Zero)
e.VisualItem.Layout.RightPart.Margin = New Windows.Forms.Padding(2, 0, 0, 0)
End If

If rlvScanForms.ViewType = Telerik.WinControls.UI.ListViewType.IconsView Then
If myViewElement.Items(0).Tag IsNot Nothing Then
e.VisualItem.Text = myText
End If
End If

End If

 

myViewElement.Items(0).Tag holds a class that contains the text I'd like to display along with the correct icon size (these are documents of various sizes so I'd like the icons to have the same width/height ratio.

myViewElement.Items(0).Tag is clearly WRONG...it's there and not Nothing but it's the 0 index of all Items in the RadListView and it's in my code as a place holder so I could build the rest of the UI class.

Does anyone know how I can get the index of the ListViewItem that's being "formatted" by VisualItemFormatting?  Of not the index from the RadListView's Item collection, maybe the actual ListViewItem object itself?

Any help would be appreciated.

Thank

 

Curtis
Top achievements
Rank 1
Iron
Iron
Veteran
commented on 20 Feb 2025, 05:58 PM | edited

Found it!

2 Answers, 1 is accepted

Sort by
0
Accepted
Curtis
Top achievements
Rank 1
Iron
Iron
Veteran
answered on 20 Feb 2025, 10:59 PM

All I needed was a good night's sleep!  The answer (of COURSE) was staring me in the face.

Here's what I was looking for:  The answer was e.VisualItem.Data - I should have known it would be something simple!  It's Telerik :)

This will give you a ListView that displays a variable sized icon (with ViewType = IconsView) along with custom text per 'cell' (I still dont know what to call this, so i'm calling it a 'cell')

Private Sub rlvScanForms_VisualItemFormatting(sender As Object, e As Telerik.WinControls.UI.ListViewVisualItemEventArgs) Handles rlvScanForms.VisualItemFormatting

    If e.VisualItem.Data.Tag IsNot Nothing Then

        Dim myScanFormIcon As ScanFormIcon = e.VisualItem.Data.Tag
        Dim myWidth As Integer = myScanFormIcon.IconSize.Width
        Dim myHeight As Integer = myScanFormIcon.IconSize.Height
        Dim myText As String = myScanFormIcon.DisplayString

        If e.VisualItem.Data.Image IsNot Nothing Then
            e.VisualItem.Image = e.VisualItem.Data.Image.GetThumbnailImage(myWidth, myHeight, Nothing, IntPtr.Zero)
            e.VisualItem.Layout.RightPart.Margin = New Windows.Forms.Padding(2, 0, 0, 0)
        End If

        If rlvScanForms.ViewType = Telerik.WinControls.UI.ListViewType.IconsView Then
            e.VisualItem.Text = myScanFormIcon.DisplayString
        End If
    End If
End Sub

  

Problem solved!

Kindest regards everyone!

-LK

0
Nadya | Tech Support Engineer
Telerik team
answered on 21 Feb 2025, 01:14 PM

Hello, Curtis,

I am really glad to hear that you managed to find a solution for your needs. Through the event arguments in VisualItemFormatting, you have access to VisualItem. The VisualItem.Data property gives you RadListDataItem which is your data object. 

The following article provides more information and examples when formatting items in RadListView. I believe it should be useful to anyone searching in this forum on a similar topic: Formatting Items - RadListView - Telerik UI for WinForms

If you have any other questions, I would be glad to help.

Regards,
Nadya | Tech Support Engineer
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.

Curtis
Top achievements
Rank 1
Iron
Iron
Veteran
commented on 21 Feb 2025, 07:18 PM

Thank you Nadya!

I agree, that article was terrific for me during development - but sadly, it never mentions VisualItem.Data so I was lost before I could even get to the formatting!

Telerik WinForms :)  Gotta love it!  I do!

Tags
ListView
Asked by
Curtis
Top achievements
Rank 1
Iron
Iron
Veteran
Answers by
Curtis
Top achievements
Rank 1
Iron
Iron
Veteran
Nadya | Tech Support Engineer
Telerik team
Share this question
or