Code for formatting the subset
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 it lacked a detail that makes all the
difference: set Useitemstyleforsubitems property.
When you create your items to popular the Listview they must have the
Useitemstyleforsubitems property set to false.
When the value is true, each Subitem will have the same style
configured in Item, even if you change your background color, font,
etc....
MSDN Documentation - Useitemstyleforsubitems
In short:
When popular 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 subitem listview