Click here to Skip to main content
15,946,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a datagridview that looks like this :[^]

and I want to resize my table inside so that it fits it exactly. Do you have any idea on how to do it?

What I have tried:

I tried this:

this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

but it doesn't work for the rows.
Updated 12-Jul-23 6:16am

1 solution

That's because as the name implies that only affects Columns.

Rows are different: under normal circumstances they are all the same height, and if there is too much data to fit in the column width the data is truncated and an ellipsis added to indicate that to the user. If you want the row height to change with the data the row contains, you need to set the DefaultCellStyle.WrapMode to DataGridViewCellStyle.True, and the AutoSizeRowsMode to DataGridViewAutoSizeRowsMode.AllCells
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900