好像只能自画。Private Function SetBackColor(lvList As ListView, picBoard As PictureBox, strItem As String) Dim iWidth As Single, iHeight As Single, tHeight As Single, lMatch As Single Dim i As Long Dim j As Long Dim mItems() As String Dim intIndex As Double
mItems = Split(strItem, ",") With picBoard .AutoRedraw = True .BackColor = lvList.BackColor .Cls .Visible = False .ScaleMode = vbTwips .Width = lvList.Width + 100 .Height = lvList.ListItems(1).Height * (lvList.ListItems.Count + 1) With .Font .Size = lvList.Font.Size + 2.75 .Bold = lvList.Font.Bold .Charset = lvList.Font.Charset .Italic = lvList.Font.Italic .Name = lvList.Font.Name .Strikethrough = lvList.Font.Strikethrough .Underline = lvList.Font.Underline .Weight = lvList.Font.Weight End With iWidth = .Width For i = 1 To lvList.ListItems.Count If i = 1 Then lMatch = lvList.ListItems(i).Top - lvList.ListItems(i).Height tHeight = lvList.ListItems(i).Top - lvList.ListItems(i).Height - lMatch iHeight = lvList.ListItems(i).Height For j = 0 To UBound(mItems) - 1 intIndex = CLng(mItems(j)) If lvList.ListItems(i).Index = intIndex Then picBoard.Line (0, tHeight)-(iWidth, tHeight + iHeight), vbYellow, BF Exit For Else picBoard.Line (0, tHeight)-(iWidth, tHeight + iHeight), vbWhite, BF End If Next Next End With lvList.Picture = picBoard.Image End Function这里的strItem是要设置的ListView的Item的Index的集合,以逗号隔开的 比如要设置背景色的是Index=2,4,6,那么strItem="2,4,6"
Dim iWidth As Single, iHeight As Single, tHeight As Single, lMatch As Single
Dim i As Long
Dim j As Long
Dim mItems() As String
Dim intIndex As Double
mItems = Split(strItem, ",")
With picBoard
.AutoRedraw = True
.BackColor = lvList.BackColor
.Cls
.Visible = False
.ScaleMode = vbTwips
.Width = lvList.Width + 100
.Height = lvList.ListItems(1).Height * (lvList.ListItems.Count + 1)
With .Font
.Size = lvList.Font.Size + 2.75
.Bold = lvList.Font.Bold
.Charset = lvList.Font.Charset
.Italic = lvList.Font.Italic
.Name = lvList.Font.Name
.Strikethrough = lvList.Font.Strikethrough
.Underline = lvList.Font.Underline
.Weight = lvList.Font.Weight
End With iWidth = .Width For i = 1 To lvList.ListItems.Count
If i = 1 Then lMatch = lvList.ListItems(i).Top - lvList.ListItems(i).Height
tHeight = lvList.ListItems(i).Top - lvList.ListItems(i).Height - lMatch
iHeight = lvList.ListItems(i).Height
For j = 0 To UBound(mItems) - 1
intIndex = CLng(mItems(j))
If lvList.ListItems(i).Index = intIndex Then
picBoard.Line (0, tHeight)-(iWidth, tHeight + iHeight), vbYellow, BF
Exit For
Else
picBoard.Line (0, tHeight)-(iWidth, tHeight + iHeight), vbWhite, BF
End If
Next
Next
End With
lvList.Picture = picBoard.Image
End Function这里的strItem是要设置的ListView的Item的Index的集合,以逗号隔开的
比如要设置背景色的是Index=2,4,6,那么strItem="2,4,6"
我用的是5.0组件,sp2系统的。换6.0组件就可以了汗
应该改为For j = 0 To UBound(mItems)
谢谢啦