First of all, I looked up this related question in here but the solution dataGridView1.Rows.Add() doesn\'t work in my case.
In my Datagridview, I have
After adding a new row, you have to set the row index in boundary of row count. You have to do these steps.
First, add row in DataGridView:
dataGridView1.Rows.Add();
Second, set new row index to count - 1:
int RowIndex = dataGridView1.RowCount - 1;
Then at last, set the controls values in it:
DataGridViewRow R = dataGridView1.Rows[RowIndex];
R.Cells["YourName"].Value = tbName.Text;
And if your datagrid's source is datattable you have to add row in that table.Give new values to the newly added row in data table and at last rebind the datagrid with updated datatable.
DataRow row = dt.NewRow();
row["columnname"] = tbName.Text.toString();
dt.Rows.Add(row);
dt.AcceptChanges();
dataGridView1.DataSource = dt;
dataGridView1.DataBind();
Check if you have set the index of the new row properly. Perhaps that's why you are getting this error.