This is a migrated thread and some comments may be shown as answers.
How to change radlistview custom item backcolor
2 Answers 21 Views
This is a migrated thread and some comments may be shown as answers.
Fernando
Top achievements
Rank 1
Fernando asked on 21 Mar 2018, 09:00 PM

Hello,

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
       Else
          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)
             Else
                e.VisualItem = New CustomListViewItemListType(Color.Blue)
             End If
             aux = aux + 1
          Next
       End If
    End Sub

 

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

 

End Class



2 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 22 Mar 2018, 02:38 PM
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.

Regards,
Dimitar
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.
0
Fernando
Top achievements
Rank 1
answered on 22 Mar 2018, 03:58 PM
Thanks Dimitar, With your example I was able to do it as I wanted. Thanks again for your help.
Asked by
Fernando
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Fernando
Top achievements
Rank 1
Share this question
or