In C# how do you make the columns in a DataGrid AutoFit Column Width like you can in Excel? Currently my five columns are fixed width but the column headers can change so I would like the columns to autofit to the width of the column.
Thanks
In C# how do you make the columns in a DataGrid AutoFit Column Width like you can in Excel? Currently my five columns are fixed width but the column headers can change so I would like the columns to autofit to the width of the column.
Thanks
There's a property on the DataGridView called AutoSizeColumnsMode which is an enum. The available values are:
AllCells
AllCellsExceptHeader
ColumnHeader
DisplayedCells
DisplayedCellsExceptHeader
Fill
None
To take BFree's answer a step further:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.autoresizecolumns.aspx