Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi

I have a DataGridView with fixed number of rows and columns

I want to change the rows height according to the whole form size - for example if i maximize the form i want the rows height to increase accordingly

How can i achieve that?

thanks

dj

What I have tried:

Handling the Resize event - and changing there all the rows heights manually
Posted
Updated 20-Sep-19 5:54am
Comments
Maciej Los 11-Apr-18 3:40am    
Why?

That's complicated, because it's not the row height that is the controlling factor in this - it's the cell content size, which normally means the font size of the text it is displaying.
Yes, you can resize the cells each time the DGV changes, but unless the font size changes, all that means is that the text is displayed the same in a bigger white space. And matching font size to "total DGV size" isn't simple: they don't use the same units of measurement so it isn't a trivial job at all.

I'd see if I could rethink this: Windows Forms isn't good at automatic resizing of controls at all, so redesigning your UI could be a better move than faffing around with trying to get it to work - because there will always be cases when it doesn't look at all good!
WPF is pretty good at it: wpf - How to make all controls resize accordingly proportionally when window is maximized? - Stack Overflow[^] provided you pick your UI elements carefully!
 
Share this answer
 
Got it!

Set the RowTemplate Resizeable to true

and then handling the dataGridView resize event
 
Share this answer
 
Hi Dude ,

You can give like this

dataGridView.RowTemplate.Height = 35;
 
Share this answer
 
Comments
Maciej Los 11-Apr-18 3:42am    
OP wrote: "i want the rows height to increase accordingly"
How does your code is related to OP's question?
dj4400 11-Apr-18 4:39am    
dataGridView.RowTemplate.Height = 35;

doesn't work
// before binding it to dataset

DataGridView1.RowTemplate.Height = 40;

// bind data with dataset
 
Share this answer
 
Comments
Richard Deeming 20-Sep-19 12:18pm    
It wasn't the right answer when it was posted last April (Solution 2). What makes you think it will be the right answer now?

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