Click here to Skip to main content
15,922,894 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can someone tell me how to change the text color of a listview item depending on the text value. I am a bit stumped on this.

C#
ListViewItem lView = new ListViewItem();
lView.Text = "Main text";

if (productinfo.IndexOf("(SALE)", StringComparison.OrdinalIgnoreCase) > -1)
{
    lView.SubItems[1].ForeColor = Color.Red;
    lView.SubItems.Add(productprice);
}
lView.SubItems.Add(moreinfo);
lView.SubItems.Add(details);
lView.SubItems.Add(ability);
lView.SubItems.Add(links);
listView.Items.Add(lView);


Thanks
Posted

1 solution

you can implement this requirement with DrawItem event, for example if this is Winform ListView Control check the documentation below;
ListView.DrawItem Event[^]
 
Share this answer
 
Comments
theadmin 15-Jul-15 9:06am    
Is this the only way it can be done? Is there not an easier way than custom drawing?

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