set anyListitem of a listview to any color
Some articles in web just demonstrate how to set the bgcolor of a listitem with equal space,but some time ,we need set the color with the value of the listitem.
the following code demonstrate how can i do it.
Private Sub SetListItemColor(lv As ListView, picBg As PictureBox)
Dim i As Integer
Dim mItem As ListItem
picBg.BackColor = lv.BackColor
lv.Parent.ScaleMode = vbTwips
picBg.ScaleMode = vbTwips
picBg.BorderStyle = vbBSNone
picBg.AutoRedraw = True
picBg.Visible = False
picBg.Width = lv.Width
picBg.Height = lv.ListItems(1).Height * (lv.ListItems.Count)
picBg.ScaleHeight = lv.ListItems.Count
picBg.ScaleWidth = 1
picBg.DrawWidth = 1
For i = 1 To 33
Set mItem = lv.ListItems(i)
If mItem.Checked = False Then
If i Mod 2 = 0 Then
picBg.Line (0, i - 1)-(1, i), RGB(254, 209, 199), BF
Else
picBg.Line (0, i - 1)-(1, i), RGB(20, 54, 199), BF
End If
Else
picBg.Line (0, i - 1)-(1, i), RGB(254, 200, 100), BF
End If
Next
lv.Picture = picBg.Image
End Sub
Screensnap:
Download Sample Project