添加到列表视图后无颜色

问题描述:

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 the
lv.UseItemStyleForSubItems = False

Sorry!

找到的分辨率:对于ListViewItem变量lv,将属性UseItemStyleForSubItems设置为false.
根据MSDN关于属性ForeColorBackColor的主题:

如果拥有子项目的ListViewItemUseItemStyleForSubItems属性设置为true,则设置此属性无效.
已测试.

祝你好运.

—SA
The resolution found: for the ListViewItem variable lv, set the property UseItemStyleForSubItems to false.
According to MSDN on the topic of properties ForeColor and BackColor:

If the UseItemStyleForSubItems property of the ListViewItem that owns the subitem is set to true, setting this property has no effect.
Tested.

Good luck.

—SA