How to calculate DataGridView.Rows.Height?

How to calculate dgv.Rows.Height

int x = dgv1.Rows.Height  

Rows.Height or dgv1.RowsHeight does not exist.

+5
source share
2 answers

The height of the lines can vary, so try the line you want:

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

Alternatively, I think it is also available from the template:

int x = dgv1.RowTemplate.Height;
+8
source

If you need a combined column header height and all rows, try:

int x = dgv1.ColumnHeadersHeight + dgv1.Rows.Cast<DataGridViewRow>().Sum(r => r.Height);
+1
source

All Articles