Multiple lines in a DataGridView cell

I don't know if this will satisfy you, but you can use Environment.NewLine to create simple line break inside cell.

Example:

string nl = Environment.NewLine; // new line variable
string data = "1 2 3" + nl + "4 5 6" + nl + "7 8 9";

Added later:

As Adrian said in comments - you will need to:

  1. Set the WrapMode for the DataGridViewColumn to DataGridViewTriState.True

  2. Make sure you set a height for the row, or set the DataGridView's AutoSizeRowsMode to DataGridViewAutoSizeRowsMode.AllCells

If you don't want to edit that column - you can set DataGridView.Column.ReadOnly property to true.

Update: It took me a while to find this property with the above information. In VS C# 2017 the WrapMode property is located in the datagridview DefaultCellStyle dialog.


as a supplement:

dataGridView.Columns[x].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
dataGridView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;

x = Column-Index