不同的列表视图项的背景颜色 [英] Varying ListViews item background color
问题描述
我怎样才能让这个一个列表视图控件的物品背景颜色从项目而异项像Winamp的,不断变化的列标题的颜色沿着?
How can I make it so that a ListViews control's background color for items varies from item to item like in WinAmp, along with changing the column header colors?
如果你仔细观察,你可以看到的第一个项目是一个暗灰色的,第二个是黑等。
If you look closely you can see the first item is a dark gray and the second is black and so on.
推荐答案
您可以设置 ListViewItem.BackColor
属性,但是这必须手动完成每个交替行。另外,您可以使用 DataGridView的
其中有一个 AlternateRowStyle
属性,会自动做到这一点 - 尽管你需要数据绑定你行了各种各样的集合这是完全是另外一个话题。
You can set the ListViewItem.BackColor
property, however this has to be done manually for each alternating line. Alternatively you could use a DataGridView
which has an AlternateRowStyle
property that would do this automatically - albeit you'll need to databind your rows in a collection of sorts which is a whole other topic.
有关的简单情况:
foreach (ListViewItem item in listView1.Items)
{
item.BackColor = item.Index % 2 == 0 ? Color.Red : Color.Black;
}
这篇关于不同的列表视图项的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!