Shannon Shang-I think therefore I am

We came here, you and I, to this place and this profession, to be great, to do great things, and give form to great dreams - and we have

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

    '-----------------------------

    'custom.such as

    '------------------------------

    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

Comments

ch21st said:

# September 24, 2004 2:28 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)