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
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;