protected override void OnDrawSubItem(DrawListViewSubItemEventArgs e)
{
//System.Diagnostics.Debug.WriteLine(String.Format("OnDrawSubItem ({0}, {1})", e.ItemIndex, e.ColumnIndex));
// Don't try to do owner drawing at design time
if (this.DesignMode) {
e.DrawDefault = true;
return;
}
// Calculate where the subitem should be drawn
Rectangle r = e.Bounds;
// Optimize drawing by only redrawing subitems that touch the area that was damaged
//if (!r.IntersectsWith(this.lastUpdateRectangle))
// return;
// Get the special renderer for this column. If there isn't one, use the default draw mechanism.
OLVColumn column = this.GetColumn(e.ColumnIndex);
IRenderer renderer = column.Renderer ?? this.DefaultRenderer;
// Get a graphics context for the renderer to use.
// But we have more complications. Virtual lists have a nasty habit of drawing column 0
// whenever there is any mouse move events over a row, and doing it in an un-double-buffered manner,
// which results in nasty flickers! There are also some unbuffered draw when a mouse is first
// hovered over column 0 of a normal row. So, to avoid all complications,
// we always manually double-buffer the drawing.
// Except with Mono, which doesn't seem to handle double buffering at all :-(
Graphics g = e.Graphics;
BufferedGraphics buffer = null;
bool avoidFlickerMode = true; // set this to false to see the problems with flicker
if (avoidFlickerMode) {
buffer = BufferedGraphicsManager.Current.Allocate(e.Graphics, r);
g = buffer.Graphics;
}
g.TextRenderingHint = ObjectListView.TextRenderingHint;
g.SmoothingMode = ObjectListView.SmoothingMode;
// Finally, give the renderer a chance to draw something
e.DrawDefault = !renderer.RenderSubItem(e, g, r, ((OLVListItem)e.Item).RowObject);
if (buffer != null) {
if (!e.DrawDefault)
buffer.Render();
buffer.Dispose();
}
}