Change the Row Height Of A DataGridView

  • Thread starter Thread starter IndigoMontoya
  • Start date Start date
I

IndigoMontoya

Guest
I have a function where I am making modifications to multiple datagridviews. I want to change the row height, and I thought the last two lines of this code would do it, but for some reason the rows are not changing size.


Can someone with more knowledge of windows forms and datagridviews help me with C# code behind to change the row height?


```
void sizeDGV(DataGridView dgv)
{
DataGridViewElementStates states = DataGridViewElementStates.None;
dgv.ScrollBars = ScrollBars.None;
var totalHeight = dgv.Rows.GetRowsHeight(states);// + dgv.ColumnHeadersHeight;
var totalWidth = dgv.Columns.GetColumnsWidth(states) + dgv.RowHeadersWidth;
dgv.ClientSize = new Size(totalWidth, totalHeight);

foreach (DataGridViewRow dgvr in dgv.Rows)
dgvr.DefaultCellStyle.BackColor = System.Drawing.SystemColors.Control;

dgv.ColumnHeadersVisible = false;
dgv.ClearSelection();

dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
dgv.ColumnHeadersHeight = 4;
}
```

Continue reading...
 
Back
Top