• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1867
  • Last Modified:

Alternate Row Colors in Listview, VB.NET

My program runs a report, fills out a list view and after completing, it runs the code below.

It's supposed to make the entire row's background white, but it only makes the first column that color.  it alternates like it's supposed to, just doesn't do all the columns.

I'm not sure if there is a property that would control this or not.

Any ideas?

Thanks for your help!

 
Dim iView As Integer = itemView1.Items.Count - 1

        For i = 1 To iView Step 2
            itemView1.Items(i).BackColor = Drawing.Color.WhiteSmoke
        Next i

Open in new window

0
slightlyoff
Asked:
slightlyoff
  • 2
  • 2
1 Solution
 
CodeCruiserCommented:
I think you need to set the subitems as well.

For i = 1 To iView Step 2
            itemView1.Items(i).BackColor = Drawing.Color.WhiteSmoke
            itemView1.Items(i).Subitems(1).BackColor = Drawing.Color.WhiteSmoke
            itemView1.Items(i).Subitems(2).BackColor = Drawing.Color.WhiteSmoke
            ...
Next i
0
 
slightlyoffAuthor Commented:
Hello!  thanks for the reply.

I gave that a try - but still, only the first column changed.

My code now looks like:

        Dim iView As Integer = itemView1.Items.Count - 1
        For i = 1 To iView Step 2
            itemView1.Items(i).BackColor = Drawing.Color.WhiteSmoke
            itemView1.Items(i).SubItems(1).BackColor = Drawing.Color.WhiteSmoke
            itemView1.Items(i).SubItems(2).BackColor = Drawing.Color.WhiteSmoke
            itemView1.Items(i).SubItems(3).BackColor = Drawing.Color.WhiteSmoke
            itemView1.Items(i).SubItems(4).BackColor = Drawing.Color.WhiteSmoke
            itemView1.Items(i).SubItems(5).BackColor = Drawing.Color.WhiteSmoke

        Next i
0
 
CodeCruiserCommented:
0
 
slightlyoffAuthor Commented:
Thanks for your help on this.  I haven't been able to get it to work - I'm sure it's something simple.  Unfortunatly, I'm going to have to leave it for now to work on a different project.

I'm going to mark it as solved though.

Thanks again!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now