This will do it for an unbound grid with three columns
in repsonse to a button click or some other event where
the user has not added the row directly to the grid
private void addRowButton_Click(object sender, EventArgs e)
{
int rowIndex = dataGridView1.Rows.Add();
DataGridViewRow row = dataGridView1.Rows[rowIndex];
row.Cells[0].Value = "test1";
row.Cells[1].Value = "test2";
row.Cells[2].Value = "test3";
dataGridView1.CurrentCell = row.Cells[0];
}
When the user does add a row to the grid by entering
data in one of the columns on the new row line the
following will work
private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
DataGridViewRow row = dataGridView1.Rows[e.RowIndex - 1];
row.Cells[0].Value = "test1";
row.Cells[1].Value = "test2";
row.Cells[2].Value = "test3";
}
Note that any user input will override values set here. This can be avoided by making
columns read only where required.