I am populating a DataGridView control on a Windows Form (C# 2.0 not WPF).
My goal is to display a grid that neatly fills all available width with cells - i.e. no un
Resume of the question:
Have column width adapt to the content (with different method across the column),
but then allow the user to set the column width...
Developing from Miroslav Zadravec's answer, for me what worked was immediately using the auto computed column.Width
to set... column.Width
!
foreach (DataGridViewColumn column in dataGridView.Columns)
{
if (/*It's not your special column*/)
{
column.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
column.Width = column.Width; //This is important, otherwise the following line will nullify your previous command
column.AutoSizeMode = DataGridViewAutoSizeColumnMode.NotSet;
}
}
//Now do the same using Fill instead of AllCells for your special column
This is tested to work when the DataGridView
is already created, using a trick like this.