我有一个带有几个子项的列表视图控件。根据记录,其中一个子项列具有红色、橙色或绿色的背景颜色。选择行时,我希望彩色子项保留其背景色,而不是被选择颜色覆盖。这可能吗?
问问题
1331 次
1 回答
3
设置ListView1.OwnerDraw
为True
。
在 ListView1 的Draw...事件中:
Private Sub ListView1_DrawColumnHeader(sender As Object, e As DrawListViewColumnHeaderEventArgs) Handles ListView1.DrawColumnHeader
e.DrawDefault = True ' let System draw this element
End Sub
Private Sub ListView1_DrawItem(sender As Object, e As DrawListViewItemEventArgs) Handles ListView1.DrawItem
e.DrawDefault = True ' let System draw this element
End Sub
Private Sub ListView1_DrawSubItem(sender As Object, e As DrawListViewSubItemEventArgs) Handles ListView1.DrawSubItem
If e.ColumnIndex = 2 Then ' only this columnindex we take over the drawing job
e.DrawBackground() ' draw the background color
e.DrawText()
Else ' other subitems, let System draw them
e.DrawDefault = True
End If
End Sub
于 2013-07-09T10:59:07.253 回答