Hi Price Brattin,
Do you mean you want to remove the last row if the last row is incomplete? Like @Karthizen says, we can remove the selected rows through programming.
> Uncommitted new row cannot be deleted.
Note that the row for new records, whichwith an asterisk in the rowheader, cann’t be removed. If we enter the cell ofnew row, and don'ttype any character, then we delete the currentnew row,it will throw the error.
Whenwe edit a cell and set the focus to another cell indifferent row (expect the now row), it trigger validation of old cell and old row and new row enter event.We'd better to comfirm the user todelete theincomplete row. Just for your convenience, I wrote the following code.
DataTable dt1;
private void Form1_Load(object sender, EventArgs e)
new DataTable("dt1");
"id");
"name");
"tag");
"a", "aaa", "a01");
"b", "bbb", "b02");
this.dataGridView1.RowEnter += new DataGridViewCellEventHandler(dataGridView1_RowEnter);
this.dataGridView1.RowsAdded += new DataGridViewRowsAddedEventHandler(dataGridView1_RowsAdded);
bool flag = false;
void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
true;
void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
if (flag == true & e.RowIndex < dataGridView1.NewRowIndex)
false;
int lastindex = dataGridView1.NewRowIndex - 1;
if (dataGridView1.Rows[lastindex].Cells[0].Value == null || dataGridView1.Rows[lastindex].Cells[1].Value.ToString() == "")
DialogResult res = MessageBox.Show(" " + (lastindex +1).ToString() + " is incomplete.\n\nDo you want to delete it?", "Note", MessageBoxButtons.YesNo);
if (res == DialogResult.Yes)
//bound
// unbound
//dataGridView1.Rows.RemoveAt(lastindex);
If I misunderstood you, or you have any other questions, please feel free to tell me.
Best regards,
Ling
Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.