Q:

Format ListView based on contents

I have a ListView that has two columns, one for a zone name and then a corresponding OK/NOK in the second column. 
I wish to format the second column based on whether it contains OK or NOK. 
I could do this quite easily with a GridView by using something similar to the following, I may be wrong, but from what I can see a ListView doesn't have the same option. 
protected void grdZoneStatus_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.Cells[1].Text == "NOK")
    {
        e.Row.Cells[1].ForeColor = Color.Red;
    }
}

So basically, how should I go about formatting a cell based on its contents within a ListView?

A:

Assuming you have a ListView called lvTest which two columns of which the second one is the relevant, this:
foreach (ListViewItem item in lvTest.Items) 
{
    if(item.SubItems[1].Text == "OK") 
        item.BackColor = System.Drawing.Color.Green;
    else 
        item.BackColor = System.Drawing.Color.Red;
}

should do the trick.

