Is there a way to set the BackColor of Winforms ListView cells individually?

北战南征 提交于 2019-12-01 08:17:46

To change the colour of a cell's BackColor, you can do this:

listView1.Items[0].UseItemStyleForSubItems = false;
listView1.Items[0].SubItems[0].BackColor = Color.Green;
listView1.Items[0].SubItems[1].BackColor = Color.Orange;
listView1.Items[0].SubItems[2].BackColor = Color.Red;
// Change the 0 in Items[0] for whatever row you want,
// and the 0, 1 or 2 in SubItems[0] to whatever column you want.

The first line,

listView1.Items[0].UseItemStyleForSubItems = false;

Will make it so that the row of cells is not all coloured the same colour.

Here is a demo picture:

Hope this helps!

If you use this property, then it works:

myListView.Items[i].UseItemStyleForSubItems = false;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!