I am implementing a custom control which derives from ListView.
I would like for the final column to fill the remaining space (Quite a common task), I have gone abou
You need to override the protected method SetBoundsCore() and perform the column resizing either before or after delegating to base.SetBoundsCore(), depending on whether the ListView width is narrowing or widening.
The following example is hardcoded for a single column ListView:
protected override void SetBoundsCore( int x, int y, int width, int height, BoundsSpecified specified )
{
ResizeColumns( width, true );
base.SetBoundsCore( x, y, width, height, specified );
ResizeColumns( width, false );
}
private void ResizeColumns( int controlWidth, bool ifShrinking )
{
if( Columns.Count < 1 || Parent == null )
return;
int borderGap = Width - ClientSize.Width;
int desiredWidth = controlWidth - borderGap;
if( (desiredWidth < Columns[0].Width) == ifShrinking )
Columns[0].Width = desiredWidth;
}
Note his code doesn't deal with the specified parameter, i'll leave that up to you!