Datatable add value to a specific Row.Column index.

  • Thread starter Thread starter labjac
  • Start date Start date
L

labjac

Guest
Hallo

I've been trying to understand how to address a specific row and column in a datatable, we created a grid which will be filled by numbers from a loop, but I cannot find a way to address the datatable eg. dt.Rows[1].Column[6] = 100 to add for instance a value to Rows 1 Column 6..

Below the matrix, if there is a way please let us know.. I don't have fixed value and will need to be able to control the index for both the row and the columns.

public static DataTable CreateSetTableMatrix(string TableName,int NrColumns, int NrRows)
{
DataTable dt = new DataTable();
dt.TableName = TableName;


int countRows = 1;
int countColumns = 1;

dt.Columns.Add("ID", typeof(string));

while (countColumns <= NrColumns)
{
dt.Columns.Add("C" + countColumns.ToString(),typeof(String));
countColumns++;
}

while (countRows <= NrRows)
{
dt.Rows.Add("R" + countRows.ToString());
countRows++;
}
//dt.Clear();
return dt;
}

Result of above method.

1603580.jpg



labjac

Continue reading...
 
Back
Top