I've got a basic owner-drawn listview (in Details mode) set up with the following handlers:
void SinkHandlerDrawColumnHeader(Object Sender, DrawListViewColumnHeaderEventArgs E)
{
E.DrawDefault = true;
}
void SinkHandlerDrawItem(Object Sender, DrawListViewItemEventArgs E)
{
E.DrawDefault = true;
TrackingMessage Data = (TrackingMessage)E.Item.Tag;
E.Item.SubItems[0].Text = Data.Line().ToString();
E.Item.SubItems[1].Text = Data.Message();
}
void SinkHandlerDrawSubItem(Object Sender, DrawListViewSubItemEventArgs E)
{
E.DrawDefault = true;
}
While the above code works, the listview is constantly being redrawn whenever it's visible. Any idea why?
EDIT: The problem was with my modifying the subitem text inside the owner draw handler. Using E.Graphics.DrawString to render the text instead fixed the issue.
Per my comment, changing data in a paint event is usually a bad design. Paint events should just paint, and very little else. By changing the data in the paint event, you were forcing the paint event to draw itself again and again.
If you need to modify the data, you need a different event.