I am trying to programmatically change the ForeColor and BackColor properties of subitems in a listview. Why doesn’t this work

Platform: WinForms| Category: ListView

Make sure the item’s UseItemStyleForSubItems property is set to false.

ListViewItem item1 = new ListViewItem('item1',0);
//this line makes things work
item1.UseItemStyleForSubItems = false;

//set fore & back color of next sub item
item1.SubItems.Add('1', Color.Black, Color.LightGreen, Font);

item1.SubItems.Add('44');
item1.SubItems.Add('3');

//As long as UseItemStyleForSubItems is false, you can later set the colors with code such as
item1.SubItems[2].BackColor = Color.Pink;

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.