c# datagridview column autosizemode

ghiboz picture ghiboz · Jun 7, 2013 · Viewed 14.1k times · Source

I wish that by default the columns uses the

AutoSizeMode = DisplayedCells;

but I wish also the possibility to resize the columns, but DisplayedCells type doesn't allow to resize..

any ideas?

Answer

John picture John · Dec 3, 2013

You can call the sub DataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells) whenever it's convenient, such as after you've loaded the data. Leave the DataGridView.AutoSizeColumnsMode property alone and the user will still be able to resize the columns themselves, but they'll have a comfortable start. Best of both worlds.