How to change radlistview custom item backcolor

3 posts, 1 answers
  1. Fernando
    Fernando avatar
    25 posts
    Member since:
    Nov 2011

    Posted 21 Mar 2018 Link to this post


    I'm trying to make a list with alternating row colors  like the one in the attached image but I'm having troubles making the rows with different colors, it only get the

    last one.

    I'm attaching the code:

    Any help will be appreciated.

    Kind regards.

    Private Sub lstProductos_VisualItemCreating(sender As Object, e As ListViewVisualItemCreatingEventArgs) Handles listViewMSProductos.VisualItemCreating
           If Me.listViewMSProductos.ViewType = ListViewType.IconsView Then
              e.VisualItem = New CustomListViewItemIconType(IdApp)
              e.VisualItem.ImageLayout = ImageLayout.Center
              e.VisualItem.ImageAlignment = ContentAlignment.TopCenter
              e.VisualItem.TextAlignment = ContentAlignment.BottomCenter
              Dim aux As Integer = 1
              For Each item In listViewMSProductos.ListViewElement.ViewElement.Items
                 If aux Mod (2) = 0 Then
                    e.VisualItem = New CustomListViewItemListType(Color.Red)
                    e.VisualItem = New CustomListViewItemListType(Color.Blue)
                 End If
                 aux = aux + 1
           End If
        End Sub


    Public Class CustomListViewItemListType    
    Inherits SimpleListViewVisualItem
    Public Sub New( pColor As Color)  
          Me.BackColor = _color
       End Sub


    End Class

  2. Answer
    Dimitar avatar
    2960 posts

    Posted 22 Mar 2018 Link to this post

    Hello Fernando,

    First I want to say that you do not need to iterate the items in the VisualItemCreating event. This event will be fired for each item.

    The proper place to style the items is the VisualItemFormatting event where you have an access to the item element. I have attached a small example that shows how you can create alternating item color functionality. 

    I hope this will be useful. Let me know if you have additional questions.

    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Fernando
    Fernando avatar
    25 posts
    Member since:
    Nov 2011

    Posted 22 Mar 2018 Link to this post

    Thanks Dimitar, With your example I was able to do it as I wanted. Thanks again for your help.
Back to Top