I am having incredible difficulties deleting a row from a bound DataGridView. I'm using VB.Net 2005. I have a datagridview that is bound to a single SQL Server table. When I go to delete a row from the grid...I check the rowcount of the DataTable before the actual deletion occurs. The count is as it should be. When the deletion occurs, the rowcount is decremented by 1 in the datatable. That works fine, however, when I update the DataAdapter....the changes do not take. I have no idea what could be happening. I don't know if I need to set certain properties in the grid or what. I have set the "AllowUserToDeleteRows" property to true. Other than that, I don't know.
PLEASE HELP!!!!!!!
Here's the code.
Private Sub grd_CellDoubleClick1(ByVal
sender As Object, ByVal e As System.Windows.Forms.DataG
ridViewCel
lEventArgs
) Handles grd.CellDoubleClick
Try
Dim row As DataRow = Nothing
strProcedure = "grd_CellDoubleClick"
stcConsignees.supplier = grd.CurrentRow.Cells(0).Va
lue
stcConsignees.terminal = grd.CurrentRow.Cells(1).Va
lue
stcConsignees.consignee = grd.CurrentRow.Cells(2).Va
lue
Dim f As New frmAdventXREF
f.ShowDialog()
If mblnDeleteRecord Then
MessageBox.Show(dtConsigne
es.Rows.Co
unt & " Records before Delete!")
Dim row1 As DataGridViewRow
row1 = grd.SelectedRows(0)
dsConsignees.Tables(0).Row
s.RemoveAt
(row1.Inde
x)
End If
Catch ex As Exception
MessageBox.Show(ex.Message
)
End Try
End Sub
'
'
'
Private Sub frmAdventSearch_FormClosin
g(ByVal sender As Object, ByVal e As System.Windows.Forms.FormC
losingEven
tArgs) Handles Me.FormClosing
If mblnDeleteRecord Then
daConsignees.Update(dsCons
ignees, "tblConsignees")
mblnDeleteRecord = False
mRecordCount = dtConsignees.Rows.Count
MessageBox.Show(mRecordCou
nt & " Records after Delete!")
End If
If mblnUpdateRecord Then
Dim dsUpdate As DataSet = dsConsignees.GetChanges(Da
taRowState
.Modified)
daConsignees.Update(dsUpda
te, "tblConsignees")
mblnUpdateRecord = False
MessageBox.Show(dsUpdate.T
ables(0).R
ows.Count & " Records Updated!")
End If
If mblnInsertRecord Then
Dim dsInsert As DataSet = dsConsignees.GetChanges(Da
taRowState
.Added)
daConsignees.Update(dsInse
rt, "tblConsignees")
mblnInsertRecord = False
MessageBox.Show(dsInsert.T
ables(0).R
ows.Count & " Records Added!")
End If
End Sub