0

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);
}
user2970916
  • 1,146
  • 3
  • 15
  • 37

1 Answers1

0

In DataGridView is an event called "NewRowNeeded". So if newrowneeded is called just set

this.dataGridView1.AllowUserToAddRows = true;

and add some Rows with:

dataGridView1.Rows.Add();

hope this will help you! see you!

Xeidos
  • 342
  • 2
  • 14