Error when committing the row to the original data store
Hey Everyone...
.....error when committing the row to the original data store.....
I sometimes get this error after I delete a record from my invoice form.. It doesn't do it all the time.
But it doesn't seem to actually throw this error until I mouse_move over the datagrid column headers of my datagrid..
The following is my delete code for my invoice form...
[CODE=vb]
If (e.KeyCode()) = System.Windows.Forms.Keys.Delete And e.Shift = True Then
Try
Dim CurrentCellItem As String = DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 0)
Dim bookmark2 As String
bookmark2 = CurrentCellItem.TrimEnd(" ")
If vbYes = MsgBox("Are You Sure You Want To Delete This Part Number? " & Chr(13) & "***" & bookmark2 & "***", MsgBoxStyle.YesNo, "Delete Record Confirmation") Then
mSql = "DELETE FROM Invoices WHERE (INV_ITEM = '" & bookmark2 & "' AND INV_NUMBER = '" & Label6.Text & "')"
Dim sqlcommand As New SqlCommand(mSql, PolarisConnection)
sqlcommand.Connection.Open()
Try
sqlcommand.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show(ex.StackTrace)
End Try
sqlcommand.Connection.Close()
Try
mPartsNumber.Clear()
mSql = "Select top 100 INV_ITEM, INV_DISC, INV_LIST, INV_STCK, INV_BO, INV_AMOUNT From Invoices WHERE INV_NUMBER = '" & Label6.Text & "'"
mDa = New SqlClient.SqlDataAdapter(mSql, PolarisConnection)
mDa.Fill(PartsNumberData.Tables("mPartsNumber"))
mDa = Nothing
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Else
End If
Catch ex As Exception
MsgBox("There Are No Part's To Delete From This Invoice! ", MsgBoxStyle.Information, "Delete Record Confirmation")
End Try
[/CODE]
The following is my Mouse_move for the datagrid in my invoice form..
[CODE=vb]
Private Sub DataGrid1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseMove
Dim pt = New Point(e.X, e.Y)
Dim hti As DataGrid.HitTestInfo = DataGrid1.HitTest(pt)
If hti.Type = DataGrid.HitTestType.Cell Then
DataGrid1.CurrentCell = New DataGridCell(hti.Row, hti.Column)
Dim current As Integer
For current = 0 To PartsNumberData.Tables(0).Rows.Count - 1
Try
If DataGrid1.IsSelected(current) Then
DataGrid1.UnSelect(current)
Else
End If
Catch ex As Exception
End Try
Next current
DataGrid1.Select(hti.Row)
End If
End Sub
[/CODE]
I put a test in the above code to determine if it was a column header and it still gave me the error.