Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 369363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:54:45+00:00 2026-05-12T13:54:45+00:00

Is it possible to ownerdraw the entire column header section of a listview? (including

  • 0

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 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T13:54:45+00:00Added an answer on May 12, 2026 at 1:54 pm

    I’m surprised by Jeffery Tan’s answer in that post. His solution cannot work, since the code tries to draw outside of the header control client area. The hDC used within custom drawing (and hence owner drawing) is for the client area of the control, and so cannot be used to paint in the non-client area. The area to the right of the right most column in a header control is in non-client area. So you need a different solution.

    Possible Solutions

    1. Hi tech and partially effective

    You can enable drawing outside the client area by using the GetDC() WinAPI call:

    [System.Runtime.InteropServices.DllImport("user32")]
    private static extern IntPtr GetDC(IntPtr hwnd);
    [System.Runtime.InteropServices.DllImport("user32")]
    private static extern IntPtr ReleaseDC(IntPtr hwnd, IntPtr hdc);
    
    public static IntPtr GetHeaderControl(ListView list) {
        const int LVM_GETHEADER = 0x1000 + 31;
        return SendMessage(list.Handle, LVM_GETHEADER, 0, 0);
    }
    

    In your column draw event handler, you will need something like this:

    if (e.ColumnIndex == 3) //last column index
    {
      ListView lv = e.Header.ListView;
      IntPtr headerControl = NativeMethods.GetHeaderControl(lv);
      IntPtr hdc = GetDC(headerControl);
      Graphics g = Graphics.FromHdc(hdc);
    
      // Do your extra drawing here
      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);
    
      g.Dispose();
      ReleaseDC(headerControl, hdc);
    }
    

    But the problem with this is that since your drawing is outside the client area, Windows doesn’t always know when it should be drawn. So it will disappear sometimes, and then be redrawn when Windows thinks the header needs repainting.

    1. Low tech but ugly

    Add an extra empty column to your control, owner draw it do look however you want, make it very wide, and turn off horizontal scrolling (optional).

    I know this is horrible, but you’re looking for suggestions 🙂

    1. Most effective, but still not perfect

    Use ObjectListView. This wrapper around a .NET ListView allows you to add overlays to your list — an overlay can draw anywhere within the ListView, including the header. [Declaration: I’m the author of ObjectListView, but I still think it is best solution]

    public class HeaderOverlay : AbstractOverlay
    {
        public override void Draw(ObjectListView olv, Graphics g, Rectangle r) {
            if (olv.View != System.Windows.Forms.View.Details)
                return;
    
            Point sides = NativeMethods.GetColumnSides(olv, olv.Columns.Count-1);
            if (sides.X == -1)
                return;
    
            RectangleF headerBounds = new RectangleF(sides.Y, 0, r.Right - sides.Y, 20);
            g.FillRectangle(Brushes.Red, headerBounds);
            StringFormat sf = new StringFormat();
            sf.Alignment = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;
            g.DrawString("In non-client area!", new Font("Tahoma", 9), Brushes.Black, headerBounds, sf);
        }
    }
    

    This gives this:
    alt text

    [Reading over this answer, I think this is an example of trying too hard 🙂 Hope you find something here helpful.]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to have variable-height rows within a WinForms ListView in Details mode?
Is it possible to have variable size (owner draw) items in the Win32 ListView,
Possible Duplicate: Extracting dollar amounts from existing sql data? I have a column in
Possible Duplicate: Difference of create Index by using include column or not using Edit:
Possible Duplicate: Matlab gives wrong answer Can anyone explain to me why the following
Possible Duplicate: regex for URL including query string I have a text or message.
I have a list view and draw it with OwnerDraw . How to draw
Possible Duplicate: How do I make a request using HTTP basic authentication with PHP
Possible Duplicate: && operator in Javascript In the sample code of the ExtJS web
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.