Subitem formatting code
lsvDados.UseItemStyleForSubItems = false;//para que a formataçao do item nao se propague ao subitem
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;
}
Also informed by @Emerson js,
Your code is correct, but you lacked a detail that makes the whole
difference: set the UseItemStyleForSubItems property.
When you create your items to popular the ListView they should have the
UseItemStyleForSubItems property set to false.
When the value is true, each SubItem will have the same style
configured in the Item, even if you change its background color, font,
etc ...
MSDN Documentation - UseItemStyleForSubItems
In short:
When you populate the ListView do:
ListViewItem i1 = new ListViewItem ("1");
i1.SubItems.Add("Valor Coluna 1...");
i1.SubItems.Add("Valor Coluna 2...");
i1.UseItemStyleForSubItems = false; // para cada item Daí pode fazer a formatação normalmente.
Format subview listview