添加到列表视图后无颜色 [英] No color after add in listview

查看:61
本文介绍了添加到列表视图后无颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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


这篇关于添加到列表视图后无颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆