Free Information Technology Magazines and eBooks

Thursday, July 16, 2009

VB.NET: Alternate the Background Color for Rows in a ListView

One way to make your presentation of data on ListView be more readable is to use alternating background color on rows. For today's article, I will try to explain How to do such task in VB.NET. Listview's SubItem has a built-in BackColor to make alternate colors possible. Here is a short code to demonstrate alternating background colors in ListView.


Dim altcolor1 As Color = Color.Blue
Dim altcolor2 As Color = Color.Crimson

Dim lv As ListViewItem = ListView1.Items.Add("Test 1")
lv.SubItems.Add("Test 1")
lv.SubItems.Add("Test 1")


lv = ListView1.Items.Add("Test 2")
lv.SubItems.Add("Test 2")
lv.SubItems.Add("Test 2")
lv.BackColor = altcolor1


lv = ListView1.Items.Add("Test 3")
lv.SubItems.Add("Test 3")
lv.SubItems.Add("Test 3")
lv.BackColor = altcolor2


VB.NET: Alternate the Background Color for Rows in a ListView


For more VB.NET coding tips & tricks, subscribe now.

0 comments: