I have bound some data to a DataGrid in a WinForm. Regardless of what I did on changing the size of the columns (like AutoSizeMode
and DataGridViewAutoSizeColumnMode
), I can't get my DataGrid to fill my WinForm, and when I resize the WinForm, the Datagrid size is fixed and is not resizing with the WinForm. Either I get a scrollbar if is the dataGrid is bigger than the form, or I have a huge space left after the last column.
I have got a result like in the picture below. Can anyone help to make the datagrid fit the form, and have it resize with the Form? Thank you.
This is not my DataGrid, just a picture from the internet, but it has the same result as mine.
Here is the code
PS: I haven't found a 100% solution yet, but a workaround, the problem was that the DataGrid source was a DataTable which had a DataTableStyle, and that one resize all the columns somehow (still couldn't figure out were exactly).So my workaround was that I added an Auto Align button in the menu, which reset the columns width by calculating the DataGridView width, and just devid it by the number of the columns in the DataTable and then it resizes each column.width
in the DataTablestyle and voilà