I’m having a weird issue in a program I’m developing for .NET 3.5 using C# in Visual Studio 2010.
I’m populating a DataGridView with information and I’d like to resize the data grid columns according to the headers, but also allow the user to manually resize the colums if the data is longer than the length of the header value.
So I changed my DataGridView.AutoSizeColumnsMode = ColumnHeader. The DataGridView is now resizing the columns automatically according to the header, but suddenly I find that I can’t resize the columns manually with my mouse even though my DataGridView.AllowUserToResizeColumns property is true.
My question is how can I automatically size my data grid view columns while still allowing the user to resize the columns?
The solution from here coverted to C# and tested:Just found a better solution from MSDN. Before the DataGridView is displayed, use the
AutoResizeColumnfunction. For example: