Question [2008] Different colors per line in a ListView

How about:
VB.NET:
'0 index - 1st item:
Listview1.Items(0).Backcolor = Color.Red
'to get all the selected items to change there backColors:
Dim list As ListView.SelectedIndexCollection = Listview1.SelectedIndices
For Each index As Integer In list
  Listview1.Items(index).Backcolor = Color.Red
Next
 
Try:
VB.NET:
For index = 0 to Listview1.Items.Count -1
    If index = Mod 2 Then
        Listview1.Items(index).Backcolor = Color.Red
        Listview1.Items(index).Forecolor = Color.Blue
    Else
        Listview1.Items(index).Backcolor = Color.Blue
        Listview1.Items(index).Forecolor = Color.Red
    End If
Next
 
Hi,

I found a way to do it:
VB.NET:
        For n As Integer = 0 To ListView.Items.Count - 1
            ListView.Items.Item(n).BackColor = Color.Blue
            ListView.Items.Item(n).ForeColor = Color.Red
        Next
        For n As Integer = 0 To ListView.Items.Count - 1 Step 2
            ListView.Items.Item(n).BackColor = Color.Red
            ListView.Items.Item(n).ForeColor = Color.Blue
        Next
 
Yeah, sorry I was doing it in my head(that's a scary thing) - didn't have my computer with me, glad I could kinda help...
 
Back
Top