.Net Framework >> How to use different color to display the item text in a ListView class with View property set to "details"?

by Morten Wennevik » Fri, 27 Aug 2004 20:55:16 GMT

Hi ZhangZQ,

Do you mean the ListViewItem.BackColor property?

bool swap = false;
foreach(ListViewItem l in lv.Items)
{
if(swap)
{
l.BackColor = SystemColors.ControlText;
l.ForeColor = SystemColors.ControlLightLight;
}
swap = !swap;
}

This will cause every other line to be reverse colored.

Note that selected lines won't be affected.

If you want to set different colors in different columns you need to set UseItemStyleForSubItems = false on the listviewitems.

--
Happy coding!
Morten Wennevik [C# MVP]

Similar Threads

1. How to use different color to display the item text in a ListView class with View property set to "details"?

How to use different color to display the item text in a ListView class with
View property set to "details"?

I want to use different color for different row in the ListView.

Thank you very much!



Regards,
ZhangZQ