C# 更改列表视图中的颜色线
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13087648/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 01:35:25 来源:igfitidea点击:
Change color line in listview
提问by Igor
How change color line in listview .
for example if line == 4then line is red
如何更改 listview 中的颜色线。例如if line == 4然后line is red
采纳答案by r3su
If you want to go through the whole list and colour each item conditionally, then you can use:
如果您想浏览整个列表并有条件地为每个项目着色,则可以使用:
foreach (ListViewItem lvw in myListView.Items)
{
if (lvw.SubItems[x].ToString() == "True")
{
lvw.BackColor = Color.Red;
}
}
Or if you always want to color the item at index 4:
或者,如果您总是想为索引 4 处的项目着色:
myListView.Items[4].BackColor = Color.Red;
回答by Michal Klouda
Might the answer be as simple as following?
答案可能像下面一样简单吗?
listView1.Items[3].BackColor = Color.Red;

