You can set the value of the cell to any string value which means that you can just create the string as usual and then set the cell value.
If you have a matrix of values you need to iterate through it to be able to populate the DataTable dynamically. Here is an example for you:
DataTable myDataTable = new DataTable();
myDataTable.Columns.Add(new DataColumn("Col1"));
myDataTable.Columns.Add(new DataColumn("Col2"));
myDataTable.Rows.Add();
object[,] matrix = new object[2, 4] {
{ 0, 0, "line1", "line2" },
{ 0, 1, "line3", "line4" }, };
for(int i = 0; i<matrix.GetLength(0); ++i)
{
int row = Convert.ToInt32(matrix[i, 0]);
int column = Convert.ToInt32(matrix[i, 1]);
myDataTable.Rows[row][column] = matrix[i, 2].ToString() + Environment.NewLine + matrix[i, 3].ToString();
}
dataGrid.ItemsSource = myDataTable.DefaultView;
same cellDo you want to add comma separated values? - progrAmmarmyDataTable.Rows[RowNumber]["ColumnName"] = "Value1 " + "\nValue2" + "\nValue3". You can't use it to hold more than one value in a DataTable. - progrAmmar