Click here to Skip to main content
15,889,354 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a listview, I need to change the background color when the value isn´t within a range. I've found blocks of code but the background color won´t change.

Can help me?

What I have tried:

foreach (var i in _nominacionesFueraRango)
   {
       ListViewItem item = new ListViewItem(i.dia.ToString("d/MMMM/yyyy"));


       item.SubItems.Add(new ListViewItem.ListViewSubItem(item, i.lugar));

       if (i.cantidadFueraRango)
       {
           item.SubItems.Add(new ListViewItem.ListViewSubItem(item, i.cantidad.ToString()));
           item.SubItems[2].BackColor = Color.Red;
       }
       else
       {
           item.SubItems.Add(new ListViewItem.ListViewSubItem(item, i.cantidad.ToString()));
           item.SubItems[2].BackColor = Color.Red;

       }
Posted
Updated 15-Jun-17 7:48am

1 solution

Example:
C#
private ListViewGroup listViewGroupProblems;
var problemItem = new ListViewItem("problem1", this.listViewGroupProblems);
problemItem.SubItems.Add("Problem one");
problemItem.BackColor = Color.MistyRose;
this.listView1.Items.Add(problemItem);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900