Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

listview control - alternate backcolor 1

Status
Not open for further replies.

MDA

Technical User
Jan 16, 2001
243
US
Hi all,

I have been searching for a way to add alternate background colors to a listview control but have not had much luck.

The concept is simple. I have a listview control that is populated from a table with four fields (columns) found in a SQL DB. I just want to alternate the backcolor for each row that shows in the listview. (ex: Silver,Navy,Silver,Navy,etc.)

I have searched and searched but no solution so far. Any ideas or samples would be a great help.

Thanks again,
MDA
 
In a loop readin records using i as a counter


item.UseItemStyleForSubItems = False

If i Mod 2 = 0 Then
item.SubItems(0).BackColor = System.Drawing.SystemColors.Window
Else
item.SubItems(0).BackColor = System.Drawing.Color.LightGreen
End If

i += 1


Try that to start with, I did this a fair while ago and can't remember properly what I was doing. But you may need to loop through each subitem in a listview item and set it each column's back color as above.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top