I have an unbounded DataGridView. I am trying to eliminate the extra row being added at the end. I have set the AllowUserToAddRows to false.
// This code is adding two rows at the beginning
this.dataGridView1.AllowUserToAddRows = false;
this.dataGridView1.Rows.Add(new DataGridViewRow());
dataGridView1.NotifyCurrentCellDirty(true);
dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
dataGridView1.NotifyCurrentCellDirty(false);
I have it setup when the user right clicks on a row, they will be able to add an extra row. However, if I right click on the last row, it will add two rows.
private void addRowBelowToolStripMenuItem_Click(object sender, EventArgs e)
{
if (_selectedRow < dataGridView1.RowCount - 1)
{
dataGridView1.Rows.Insert(_selectedRow + 1, 1);
}
else
{
dataGridView1.Rows.Add();
}
dataGridView1.NotifyCurrentCellDirty(true);
dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
dataGridView1.NotifyCurrentCellDirty(false);
}