Is there a way to set the BackColor of Winforms Li

2019-02-18 21:18发布

I want to color each list view cell's BackColor using a different color. Is this possible?

2条回答
等我变得足够好
2楼-- · 2019-02-18 21:49

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:

enter image description here

Hope this helps!

查看更多
时光不老,我们不散
3楼-- · 2019-02-18 21:59

If you use this property, then it works:

myListView.Items[i].UseItemStyleForSubItems = false;
查看更多
登录 后发表回答