Answer the question
In order to leave comments, you need to log in
How to prevent deleting empty row in dataGridView?
Good afternoon, please help, the problem is that when I delete an empty row in the datagrid, I get an error in
dataGridView1.Rows.RemoveAt (e.RowIndex)
As I understand it, you need to check the row, if it is full, then deletion is possible if it is empty, then no.
Please tell me how to implement it...
Answer the question
In order to leave comments, you need to log in
Decided so
var senderGrid = (DataGridView)sender;
if (e.RowIndex == dataGridView1.NewRowIndex || e.RowIndex < 0)
return;
if (e.ColumnIndex == dataGridView1.Columns["DeleteButtonColumn"].Index)
{
dataGridView1.Rows.RemoveAt(e.RowIndex);
}
1. Either set AllowUserToDeleteRows = false
2. Or check the index before deleting a row
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question