Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate DataGridView.Rows.Height?

How to calculate dgv.Rows.Height

int x = dgv1.Rows.Height  

Rows.Height or dgv1.RowsHeight does not exists.

like image 528
Buena Avatar asked Jun 18 '12 13:06

Buena


2 Answers

Row heights can vary, so try the row you want:

int x = dgv1.Rows[0].Height;

Alternatively, I think it's also available from the template:

int x = dgv1.RowTemplate.Height;
like image 101
LarsTech Avatar answered Nov 14 '22 22:11

LarsTech


If you want the combined height of the column header and all the rows, try:

int x = dgv1.ColumnHeadersHeight + dgv1.Rows.Cast<DataGridViewRow>().Sum(r => r.Height);
like image 20
John Kurtz Avatar answered Nov 14 '22 22:11

John Kurtz