In DataGridView 2.0,there is a option to resize row to fit the content of the cell.This will increase the row height.
Expand|Select|Wrap|Line Numbers
- this.dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCells;
To make all of the rows in your DataGridView appear the same size, take the following the steps to set the max row height and set it to be the height for all the rows in dataGridView:
Step 1:
Find out the maximum row height and set the height to DataGridView preferred rowheight
Expand|Select|Wrap|Line Numbers
- void dataGridView1_RowHeightChanged(object sender, DataGridViewRowEventArgs e)
- {
- int rowHeight = e.Row.Height;
- if (this.dataGridView1.RowTemplate.Height < rowHeight)
- {
- this.dataGridView1.RowTemplate.Height = rowHeight;
- }
- }
Set the AutoSizeRowsMode to none,then apply the maximum row height to all the rows
Expand|Select|Wrap|Line Numbers
- private void dgLocation_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
- {
- int rowHeight=this.dataGridView1.RowTemplate.Height;
- this.dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
- int numRows = this.dataGridView1.Rows.Count;
- for (int i = 0; i < numRows; i++)
- {
- this.dataGridView1.Rows[i].Height = rowHeight;
- }
- }