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

后端 未结 2 2007
走了就别回头了
走了就别回头了 2021-01-14 06:05

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

相关标签:
2条回答
  • 2021-01-14 06:18

    If you use this property, then it works:

    myListView.Items[i].UseItemStyleForSubItems = false;
    
    0 讨论(0)
  • 2021-01-14 06:39

    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!

    0 讨论(0)
提交回复
热议问题