【发布时间】:2013-07-30 17:36:08
【问题描述】:
是否可以更改Listview 中特定列的特定项目的颜色?
【问题讨论】:
-
@user2214609 背景色还是前景色?
是否可以更改Listview 中特定列的特定项目的颜色?
【问题讨论】:
给定一个名为ListView1 的ListView。
如果您知道要更改的列的名称,请尝试以下操作:
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 是合成的,你可以替换任何你想要的颜色。
【讨论】:
由于您没有提到要更改的内容,所以下面是更改列表视图中特定子项的背景色和前景色的示例
item1.SubItems[1].BackColor = Color.Yellow;
item1.SubItems[1].ForeColor= Color.Yellow;
您可以通过列名指定自己的子项。
【讨论】: