I have a datagrid that is displaying the contents of a SQL table. I am trying to add a button that will delete the selected row from the datagrid. I found the following that allows me to remove it from the grid but it is not removing it from the table of course. I am drawing a blank on how to remove from the grid and the underlying table.
foreach (DataGridViewRow row in myGrid.SelectedRows)
if (!row.IsNewRow) myGrid.Rows.Remove(row);
int selectedCount = myGrid.SelectedRows.Count;
while (selectedCount > 0)
{
if (!myGrid.SelectedRows[0].IsNewRow)
myGrid.Rows.RemoveAt(myGrid.SelectedRows[0].Index);
selectedCount--;
}
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Suraj KumarRank #353 · 7.1K reputationPosted Dec 14, 2018, 6:39 PM EST
Scott G111 reputationPosted Dec 17, 2018, 2:33 AM EST