【问题标题】:Change color to Listview column item将颜色更改为 Listview 列项
【发布时间】:2013-07-30 17:36:08
【问题描述】:

是否可以更改Listview 中特定列的特定项目的颜色?

【问题讨论】:

标签: c# winforms listview


【解决方案1】:

给定一个名为ListView1ListView

如果您知道要更改的列的名称,请尝试以下操作:

foreach(ListViewItem theItem in ListView1)
{
    if(theItem.Text == "Column Name")
    {
        theItem.ForeColor = Color.Red;

        // You also have access to the list view's SubItems collection
        theItem.SubItems[0].ForeColor = Color.Blue;
    }
}

注意:显然Column Name 是虚构的,您需要替换真实的列名。另外,Color.Red 是合成的,你可以替换任何你想要的颜色。

【讨论】:

  • “ListViewItem”到底是什么?你能解释一下吗? @卡尔安德森
【解决方案2】:

由于您没有提到要更改的内容,所以下面是更改列表视图中特定子项的背景色和前景色的示例

 item1.SubItems[1].BackColor = Color.Yellow;
 item1.SubItems[1].ForeColor= Color.Yellow;

您可以通过列名指定自己的子项。

【讨论】:

    猜你喜欢
    • 2013-02-27
    • 2015-06-16
    • 2012-03-10
    • 2014-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-01
    • 2012-05-01
    相关资源
    最近更新 更多