I know I can change the OwnerDraw
property to true
and then handle the DrawColumnHeader
event but if I do it like this, I have to take
How about this:
Create a new WinForm project, drag a ListView control onto the form, set OwnerDraw = true, View = Details in the Properties pane, then handle the DrawColumnHeader event.
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.SetLastColumnWidth();
this.theListView.Layout += delegate
{
this.SetLastColumnWidth();
};
}
private void SetLastColumnWidth()
{
// Force the last ListView column width to occupy all the
// available space.
this.theListView.Columns[ this.theListView.Columns.Count - 1 ].Width = -2;
}
private void listView1_DrawColumnHeader( object sender, DrawListViewColumnHeaderEventArgs e )
{
// Fill header background with solid yello color.
e.Graphics.FillRectangle( Brushes.Yellow, e.Bounds );
// Let ListView draw everything else.
e.DrawText();
}
}
}