Ensuring text wraps in a dataGridView column
Try setting
.AutoSizeMode
to.DisplayedCells
.- Set the
AutoSizeRowsMode
toAllCells
. DataGridView.DefaultCellStyle.WrapMode
toDataGridViewTriState.True
There is no need to reinvent the wheel by repainting the cell.
Instead simply:
- Set
AutoSizeRowsMode
property toAllCells
. This allows row height to grow with any wrapped text. - Set
DataGridView.DefaultCellStyle.WrapMode
toDataGridViewTriState.True
to wrap text in the cells. - Most importantly set
DataGridView.AutoSizeColumnsMode
toDataGridViewAutoSizeColumnsMode.None
so that the columns don't resize themselves (so they remain at the user specified width).
After that the text should wrap to the next line if there is not enough space in the column.