我正在使用一些遗留代码,需要根据某些条件更改VB6中ListView中行的背景颜色(和字体颜色)。我需要在选择行而不选择行时更改行的颜色。我可以通过.Foreground属性更改未选择行的字体颜色,但我无法在任何其他方案中更改颜色。
答案 0 :(得分:2)
查看此forum post。以下是代码中的每个其他行的颜色示例:
'\\ loop through the rows to select every other row
For i = 1 To lvwBackColour.ListItems.Count
If (lvwBackColour.ListItems(i).Index Mod 2) = 0 Then
'\\ add a tick to the checkbox
lvwBackColour.ListItems(i).Checked = True
'\\ add the colour to the picturebox
'\\ See Here (http://msdn2.microsoft.com/en-us/library/aa230480(VS.60).aspx)
'\\ for information about the Line method
picBG.Line (0, i - 1)-(1, i), &H4000FF, BF
'\\ update column four caption
lvwBackColour.ListItems(i).SubItems(3) = "Hidden column value = 1"
Else
'\\ remove the tick from the checkbox
lvwBackColour.ListItems(i).Checked = False
'\\ reset backcolour to white
picBG.Line (0, i - 1)-(1, i), &HFFFFFF, BF
'\\ reset the Column Four caption
lvwBackColour.ListItems(i).SubItems(3) = "Hidden column value = 0"
End If
Next i
'\\ set the listview to use the picturebox image
lvwBackColour.Picture = picBG.Image
这是关于Line方法的msdn文章的link。
答案 1 :(得分:1)
所选行的背景颜色由系统控制。你无法将其改为其他任何东西。
如果 能够更改所选行的背景,则需要自定义绘制列表视图 - 说实话,认真考虑是太痛苦了:)