I am trying to remove one row from a datagridview when user selects a row and then clicks the "Delete" button. I am using the following code:
private void btnDel_Click(object sender, EventArgs e)
{
dgvSearchResults.ReadOnly = false;
if (MessageBox.Show("Are you sure?", "confirmation", MessageBoxButtons.YesNo) == DialogResult.Yes) {
dgvSearchResults.Rows.RemoveAt(dgvSearchResults.SelectedRows[0].Index);
ole_da.Update(dTable);
}
}
And I am getting the following error when debugging:
{"Update requires a valid DeleteCommand when passed DataRow collection with deleted rows."}
I am pretty new to C# and have no idea how to create a DeleteCommand or use CommandBuilder (as suggested in some SO posts) to solve this problem.