I just started to create my own ListView control and already have big problems...
I use the following code at the moment:
protected override void OnPaint(PaintEventArgs pe)
{
this.SuspendLayout();
if (this.View == View.Details)
{
Graphics g = pe.Graphics;
g.Clear(this.BackColor);
foreach (ListViewItem lvi in this.Items)
{
if (lvi.Selected)
g.FillRectangle(new SolidBrush(Color.LightBlue), lvi.Bounds);
g.DrawString(lvi.Text, lvi.Font, new SolidBrush(lvi.ForeColor), lvi.Bounds, StringFormat.GenericDefault);
}
}
this.ResumeLayout();
// Calling the base class OnPaint
base.OnPaint(pe);
}
The curious problem now is that everything works as expected EXPECT the first item!
I can click on it as often as I want and it´s value is selected but nevertheless, no blue rectangle is drawn...
But resizing the columns of the detail ListView brings up the blue rectangle or if the custom ListView loses
focus, the rectangle is painted too.
Can someone explain me that (in my eyes) strange behavior?
A big thanks to you!
Greetings,
timtos.