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

旧城冷巷雨未停 提交于 2019-12-01 06:23:56

问题


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


回答1:


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!




回答2:


If you use this property, then it works:

myListView.Items[i].UseItemStyleForSubItems = false;


来源:https://stackoverflow.com/questions/10958171/is-there-a-way-to-set-the-backcolor-of-winforms-listview-cells-individually

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