1
I’m trying to exclude the line on which you have the focus of a datagrid
, I have used the following code:
datagrid.Rows.RemoveAt(e.RowIndex);
Is returning the following message:
Uncommitted new Row cannot be Deleted.
What’s wrong? Can someone help me?
Amigo @Qmechanic73 if I set the Allowusertoaddrows property of Datagridview to false. No rows will appear.. There is another way. I need to always delete the last line of the datagrid.
– Fabrício Mendes
Using the Following Code
dataGridView1.AllowUserToAddRows = false;var index = e.RowIndex;if (index >= 0){ dgvCompeticao.Rows.RemoveAt(index);}
gave this exception.: Operation cannot be performed in this Event Handler.– Fabrício Mendes
@Fabríciosimonealanamendes I edited and put another way without having to touch
AllowUserToAddRows
.– stderr
your code is still damage errors Operation cannot be performed in this Event Handler.
– Fabrício Mendes
@Fabriciosimonealanamendes Try the following:
BeginInvoke(new Action(delegate { dataGridView1.Rows.RemoveAt(e.RowIndex); }));
.– stderr
@Fabriciosimonealanamendes Another thing, the property
AllowUserToAddRows
should serve this case, when false she eliminates the last blank line, not allowing the user to add Rows. How are you importing the data? I tested it here by entering data dynamically and it seemed to work well.– stderr
I’m putting the code in the event Cellenter The data is not imported, it is typed, and so I need to limit the line quantity, which will be saved in the bank
– Fabrício Mendes
@Did you get it? See if this one code works for what you intend to do.
– stderr