My code does not show errors but when I want to use the button it throws me this error, I would like to know how to solve it.
My code for the "REMOVE" button
private void BtnQuitar_Click(object sender, EventArgs e)
{
foreach(DataGridViewRow item in DataGridViewSelectionArea.SelectedRows)
{
DataGridViewSelectionArea.RemoveAt(item.Index);
}
}
If you bound the
DataGridView
to aorigen de datos
, you can't remove items directly in the control, you have to remove the row from the DataTable and rebind for it to updateOn the other hand, if you define an Id column, it should be unique for each item, there I see that you have a 1 as Test and the same 1 for Bar, if it is Id it cannot be duplicated, otherwise it ceases to be Id If you want to use them
SelectedRows
instead of the checks you could search by id, but this must be unique, then you would do:the idea is to search in the data that you linked to the Grid to eliminate these and in the end show them again