Overriding ListView OnDrawSubItem

G

Guest

I need to draw an image for one of a listview item's subitems, so I'm
creating a custom control that inherits from ListView. I've overriden the
OnDrawSubItem like this:

protected override void OnDrawSubItem(DrawListViewSubItemEventArgs e)
{
if (e.ColumnIndex == 0)
{
//e.Graphics.FillRectangle(Brushes.LightSteelBlue, new
Rectangle(0, 0, this.Columns[e.ColumnIndex].Width, 14));
//e.Graphics.DrawLine(Pens.DarkBlue, new Point(5, 10), new
Point(95, 10));
}
else
{
e.DrawDefault = true;
}
base.OnDrawSubItem(e);
}

I drop the control on a form, add items with subitems to it, and run the
project, and I get a listview with all the subitems showing correctly except
that the first column on each is blank. If I use the same method to override
OnDrawColumnHeader, the image shows up in the header. Is there something
else that needs to be done to do this kind of drawing in a listview?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top