添加到列表视图后无颜色
问题描述:
Public Sub Add_In_ListView(ByVal Field1 As String, ByVal Field2 As String, ByVal Field3 As String, ByVal Field4 As String, ByVal Field5 As String, ByVal Field6 As String, ByVal Field7 As Boolean)
lv = ListView1.Items.Add(Field1)
lv.SubItems.Add(Field2)
lv.SubItems.Add(Field3)
lv.SubItems.Add(Field4)
lv.SubItems.Add(Field5)
lv.SubItems.Add(Field6)
If Field7 = True Then
lv.SubItems.Add(6).Text = "Enable"
lv.SubItems(6).ForeColor = Color.Green
Else
lv.SubItems.Add(6).Text = "Disable"
lv.SubItems(6).ForeColor = Color.Red
End If
lv.SubItems.Add("")
lv.SubItems.Add("")
lv.SubItems.Add("")
lv.SubItems.Add("")
lv.SubItems.Add("")
ListView1.Refresh()
End Sub
当我的子例程运行正确添加时,在listviw中,带有单词enable或disable的行并没有改变颜色.
为什么?
谢谢和问候
Mea culpa
我忘记了lv.UseItemStyleForSubItems = False
抱歉!
When my subroutine run add correctly the line with the word enable or disable in the listviw BUT they did not change the color.
Why???
Thanks and regards
Mea culpa
I have forget thelv.UseItemStyleForSubItems = False
Sorry!
答
找到的分辨率:对于ListViewItem
变量lv
,将属性UseItemStyleForSubItems
设置为false
.
根据MSDN关于属性ForeColor
和BackColor
的主题:如果拥有子项目的 已测试.ListViewItem
的UseItemStyleForSubItems
属性设置为true,则设置此属性无效.
祝你好运.—SA
The resolution found: for theListViewItem
variablelv
, set the propertyUseItemStyleForSubItems
tofalse
.
According to MSDN on the topic of propertiesForeColor
andBackColor
:If the Tested.UseItemStyleForSubItems
property of theListViewItem
that owns the subitem is set to true, setting this property has no effect.
Good luck.—SA