Ensuring text wraps in a dataGridView column

前端 未结 9 1588
感动是毒
感动是毒 2021-01-01 17:41

I have dataGridView with a particular column. When I write long text in dataGridView it shows me a shortened version, with ellipses, because the column isn\'t wide enough to

9条回答
  •  星月不相逢
    2021-01-01 18:11

    There is no need to reinvent the wheel by repainting the cell.

    Instead simply:

    • Set AutoSizeRowsMode property to AllCells. This allows row height to grow with any wrapped text.
    • Set DataGridView.DefaultCellStyle.WrapMode to DataGridViewTriState.True to wrap text in the cells.
    • Most importantly set DataGridView.AutoSizeColumnsMode to DataGridViewAutoSizeColumnsMode.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.

提交回复
热议问题