I have a form with a DataGridView
and I want to set the columns AutoSizeMode
to Fill
and the grids ColumnHeadersHeightSizeMode
Thank you, Ulf, for the excellent sample showing how to reproduce this. One of my clients reported this bug to me and your sample has been invaluable.
Taking Ivan's excellent answer one step further, creating your own grid inheriting from the DataGridView
should prevent this ridiculous bug permanently. Just be sure to always use the custom grid throughout your application.
public class Grid
: DataGridView
{
protected override void OnHandleCreated(EventArgs e)
{
// Touching the TopLeftHeaderCell here prevents
// System.InvalidOperationException:
// This operation cannot be performed while
// an auto-filled column is being resized.
var topLeftHeaderCell = TopLeftHeaderCell;
base.OnHandleCreated(e);
}
}