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 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Scott GPosted Dec 17, 2018, 7:33 AM
Suraj KumarPosted Dec 14, 2018, 11:39 PM