c# runtime add rows to datagridview code example
Example 1: add row to datagridview c#
DataGridViewRow row = (DataGridViewRow)yourDataGridView.Rows[0].Clone();
row.Cells[0].Value = "XYZ";
row.Cells[1].Value = 50.2;
yourDataGridView.Rows.Add(row);
Example 2: dynamically add rows to datagridview c#
DataTable dt = new DataTable();
for (int i = 0; i < count; i++)
{
dt.Columns.Add(fromFileFields[i]);
}
for (int i = 0; i < count; i++)
{
var row = dt.NewRow();
dt.Rows.Add(row);
}
datagridview.DataSource = dt;