参考一下这个程序,大同小异的。
Public Sub gsubSetItemColor(ByVal Item As ListItem, ByVal strColor As String)
Dim intIndex As Integer
Select Case UCase(strColor)
Case "RED"
Item.ForeColor = vbRed
Case "BLUE"
Item.ForeColor = RGB(0, 155, 0)
Case Else
Exit Sub
End Select
With Item
For intIndex = 1 To .ListSubItems.Count
.ListSubItems(intIndex).ForeColor = .ForeColor
Next
End With
End Sub
Public Sub gsubSetItemColor(ByVal Item As ListItem, ByVal strColor As String)
Dim intIndex As Integer
Select Case UCase(strColor)
Case "RED"
Item.ForeColor = vbRed
Case "BLUE"
Item.ForeColor = RGB(0, 155, 0)
Case Else
Exit Sub
End Select
With Item
For intIndex = 1 To .ListSubItems.Count
.ListSubItems(intIndex).ForeColor = .ForeColor
Next
End With
End Sub
CustomDrawLV Demo.zip (5KB)
This project shows how to display any row in a listview control in a different color than the rest of the rows by subclassing the NM_CUSTOMDRAW message that is sent to the parent of the listview before each item is drawn. If you don't already have it, you will want to get the Debug Object (Dbgwproc.dll) DLL to allow stepping through subclassed code in break mode in the VB IDE.
ListView1.ListItems(1).ForeColor=vbYellowPrivate Sub Form_Load()
Dim item As ListItem
Set item = ListView1.ListItems.Add(, , "测试")
item.ForeColor = vbRed
Set item = ListView1.ListItems.Add(, , "测试111")
item.ForeColor = vbYellow
Set item = ListView1.ListItems.Add(, , "测试")
item.ForeColor = vbBlue
Set item = ListView1.ListItems.Add(, , "测试111")
item.ForeColor = vbGreen
End Sub
Private Sub Form_Load()
Dim item As ListItem
Set item = ListView1.ListItems.Add(, , "测试")
item.SubItems(1) = "测试"
item.ForeColor = vbRed
item.ListSubItems(1).ForeColor = vbRed
Set item = ListView1.ListItems.Add(, , "测试111")
item.SubItems(1) = "测试"
item.ForeColor = vbYellow
item.ListSubItems(1).ForeColor = vbYellow
Set item = ListView1.ListItems.Add(, , "测试")
item.SubItems(1) = "测试"
item.ForeColor = vbBlue
item.ListSubItems(1).ForeColor = vbBlue
Set item = ListView1.ListItems.Add(, , "测试111")
item.SubItems(1) = "测试"
item.ListSubItems(1).ForeColor = vbGreen
item.ForeColor = vbGreen
End Sub