Ensuring text wraps in a dataGridView column

前端 未结 9 1514
感动是毒
感动是毒 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:13

    I agree with the answer that discussed simply setting the WordWrap on the cell and would add to it this scenario.

    I was needing to change the colors and font styles on the fly based on the data in each cell. Initially I thought that I was stuck figuring out how to make the DrawString work with wrapping inside CellPainting event due to needing different text colors.

    However, in the end I just set the Cell.Style properties inside the CellPainting event and then exited the event without setting the e.Handled = true. This way the grid's paint event used the styles I set for each cell and the text wrapped properly.

    For example:

    datagrid1[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.Green;
    

提交回复
热议问题