views:

646

answers:

1

Is it possible to ownerdraw the entire column header section of a listview? (including the region to the right of the column headers)? ListView is in Details View.

An answer here indicates that the remaining space can be drawn along with the last column header: http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework.windowsforms/topic32927.aspx

But it does not seem to work at all - nothing is drawn outside header area.

The proposed solution is based on drawing outside of the passed Bounds:

if (e.ColumnIndex == 3) //last column index
{
    Rectangle rc = new Rectangle(e.Bounds.Right, //Right instead of Left - offsets the rectangle
            e.Bounds.Top, 
            e.Bounds.Width, 
            e.Bounds.Height);

    e.Graphics.FillRectangle(Brushes.Red, rc);
}

The ClipBounds property of the available Graphics instance indicates an unbound area (from large negative numbers to large positive). But nothing is drawn outside the columnheader area of the last column.

Does anybody have a solution for this?

+1  A: 
Grammarian
Thanks for the great answer. In our case, ObjectListView would be an overkill. Your first solution is sufficient and works well enough in our scenario. You have a small error in code - one should naturally draw onto the g instance, not onto the original e.Graphics: e.Graphics.FillRectangle(Brushes.Red, rc); //should be g.FillRectangleThe SendMessage method import is also missing: [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern IntPtr SendMessage(IntPtr handle, int messg, int wparam, int lparam);
Marek
Yes, you're quite right
Grammarian