Custom ListView problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • timtos

    #1

    Custom ListView problem

    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(PaintEv entArgs pe)
    {
    this.SuspendLay out();
    if (this.View == View.Details)
    {
    Graphics g = pe.Graphics;
    g.Clear(this.Ba ckColor);
    foreach (ListViewItem lvi in this.Items)
    {
    if (lvi.Selected)
    g.FillRectangle (new SolidBrush(Colo r.LightBlue), lvi.Bounds);
    g.DrawString(lv i.Text, lvi.Font, new SolidBrush(lvi. ForeColor), lvi.Bounds, StringFormat.Ge nericDefault);
    }
    }

    this.ResumeLayo ut();
    // 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.


Working...