Reputation: 22190
I have a datagridview in windows application form below which I put two buttons (one for zoom in and other for zoom out). Now when user press the zoom button I increase/decrease the font size inside the grid according to predefined ratio. It works fine i.e the font size reduces and increases but the only thing that not working is the size of cell or datagridview.
Every time the cell size remains fix. I want to resize my datagridview accordingly, currently i am using the following code but it doesn't work in my case :(
dataGridView1.AutoResizeColumns();
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
Note: my datagridview always contains text in it. So no need to consider other options like what if there is a button/label in a cell etc.
Upvotes: 2
Views: 2504
Reputation: 14387
you should either switch the two lines:
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
dataGridView1.AutoResizeColumns();
Or call it like this:
dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
Either way you have to do this after you have changed the font.
Upvotes: 3