Search code examples
c#winformslistviewitem

Why the listviewitem's BackColor doesn't work?


In this question, the BackColor doesn't work. My codes like this:

ListViewItem item1 = new ListViewItem();
item1.SubItems.Clear();
item1.SubItems[0].Text = "english";
item1.SubItems.Add("22");
item1.SubItems.Add("0.5");
item1.BackColor = Color.Red;
item1.ForeColor = Color.Red;
this.listView1.Items.Add(item1);

In the Form1.cs[design], it works like this:

enter image description here

But when I run the program, it doesn't work, like this:

enter image description here


Solution

  • Try this, my friend:

    ListViewItem item1 = new ListViewItem();
    item1.SubItems.Clear();
    item1.SubItems[0].Text = "english";
    item1.SubItems.Add("22");
    item1.SubItems.Add("0.5");
    item1.BackColor = Color.Red;
    item1.ForeColor = Color.Red;
    item1.UseItemStyleForSubItems = false;
    this.listView1.Items.Add(item1);