In VB2012, I have a created a student management software with SQL2012 as the back-end. The below code is used for deleting a selected record from the datagridview when DELE
the code below is also helpful
Private Sub btnRemoveItem_Click(sender As Object, e As EventArgs) Handles btnRemoveItem.Click
If datagridviewname.SelectedRows.Count > 0 Then
For i As Integer = datagridviewname.SelectedRows.Count - 1 To 0 Step -1
datagridviewname.Rows.RemoveAt(datagridviewname.SelectedRows(i).Index)
Next
Else
MessageBox.Show("Select Row to remove")
End If
End Sub
Selected row is not necessary current, from the perspective of binding source. You need to be using DataGridView.SelectedRows. Each is a DataGridViewRow, and you should be able to retrieve DataGridViewRow.DataBoundItem, cast it to DataRow
, and use Delete
on that.