Possible bug with ListViewSubItem foreColor

  • Thread starter Thread starter Laurence Bunnage
  • Start date Start date
L

Laurence Bunnage

Has anyone come across the following problem and does anybody know of a
solution.

I am using a ListView to display the age of a collection of items. When the
items are an hour old, I am using the foreColor property to set the color to
Color.Red. Everything is working exactly as expected, except for the
following problem.

In normal use the text gets displayed in the correct color. However if I
cover the control and then uncover it again, the text always gets displayed
in Black. I have checked the foreColor property and it is still showing
Red, even though the text is displayed in black. If I partially cover the
text and then uncover it, half the text is Red and half is Black. The color
is displayed correctly, next time I update the SubItem.Text property

I can only assume that there is a bug in the ListViewSubItem paint function,
called after an Invalidate, which is using the wrong color setting when
painting the control.

Any help on this would be welcome.
 
I had a similar problem, but it was a long time ago and cant remember
the exact fix. I've found my code that works and it was something to
do with having to add the items for the SubItems individually.

I've slightly edited my code but here it is. Hope this helps:

RichS.


ListViewItem lvItem = new ListViewItem(
item.Title, 0 );

lvItem.UseItemStyleForSubItems = false;

if ( true == bOld )
{
lvItem.ImageIndex = 1;
lvItem.ForeColor = SystemColors.GrayText;
}
else
{
lvItem.Font = new Font( lvItem.Font,
lvItem.Font.Style | FontStyle.Bold );
}

lvItem.SubItems.Add( text1, foreColor,
backColor, regularListViewFont );
lvItem.SubItems.Add( text2, foreColor,
darkBackColor, regularListViewFont );
lvItem.SubItems.Add( text3, foreColor,
darkBackColor, boldListViewFont );
 
Back
Top