I have trouble setting the background color of the listview SubItem when returning query from the database. I need in column # 18, which will return values such as "Overdue" and "On Day", when the value returned is="Overdue" that subitem in column 18 is red background. The code below colors the full line.
foreach (ListViewItem item in lsvDados.Items)
{
if (item.SubItems[18].Text == "VENCIDO")
item.BackColor = System.Drawing.Color.Red;
else item.BackColor = System.Drawing.Color.Green;
}
The code below does not color anything.
foreach (ListViewItem item in lsvDados.Items)
{
if (item.SubItems[18].Text == "Vencido")
item.SubItems[18].BackColor = System.Drawing.Color.Red;
else
item.SubItems[18].BackColor =System.Drawing.Color.Green;
}
How do I color only the sub item with the desired value? How would the code to scan all the listview look for some subitem with this desired value and soon after finding format it?