How to give alternative colors to Listview Control? i.e Odd number rows should be in blue color and even number rows should be in white color.

Questions by Subashini.Ramasamy   answers by Subashini.Ramasamy

Showing Answers 1 - 3 of 3 Answers

WolfEmery

  • Sep 3rd, 2009
 

Okay, I've been looking all over for a way to do this and ended up working it out for myself.  So even though this post is a few years old, I've decided to post my results.  The following code is for a multi-column (7 columns) ListView in VB.net 2005...

Private Sub ChangeRowColor()

Dim i As Integer, x As Integer

For i = 0 To ListView1.Items.Count - 1

For x = 0 To 7 ' for 7 columns

If OddEvenVal(i) = 2 Then ' Call to function to determine if row is even

Me.ListView1.Items(i).SubItems(x).BackColor = Drawing.Color.Gainsboro

End If

Next

Next

End Sub


Private Function OddEvenVal(ByVal lngValue As Long) As Integer

If lngValue And 1 Then OddEvenVal = 1 ' Odd

If (lngValue And 1) = 0 Then OddEvenVal = 2 ' Even

End Function

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions