I have a sample database that I am able to navigate, add new and update but I am falling over when it comes to deleting a record. Currently the user would navigate the record and then select delete, I have this code which seems to delete it from the view but when i re-load the form it is there again. When I add a record it saves it no problem, just seems to be a problem with delete.
VB.NET:
Imports System.Data
Public Class Window2
Dim customerdataset As New CustomersDataset
Dim customeradapter As New CustomersDatasetTableAdapters.Purchase_OrdersTableAdapter
Dim customermanager As New CustomersDatasetTableAdapters.TableAdapterManager
Dim myView As CollectionView
Private Sub Window2_Loaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles Me.Loaded
Me.customeradapter.Fill(Me.customerdataset.Purchase_Orders)
Me.DataContext = Me.customerdataset.Purchase_Orders
Me.myView = CollectionViewSource.GetDefaultView(Me.customerdataset.Purchase_Orders)
End Sub
Private Sub btnNext_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnNext.Click
If Me.myView.CurrentPosition < Me.myView.Count - 1 Then
Me.myView.MoveCurrentToNext()
End If
End Sub
Private Sub btnPrevious_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnPrevious.Click
If Me.myView.CurrentPosition > 0 Then
Me.myView.MoveCurrentToPrevious()
End If
End Sub
Private Sub btnFirst_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnFirst.Click
Me.myView.MoveCurrentToFirst()
End Sub
Private Sub btnLast_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnLast.Click
Me.myView.MoveCurrentToLast()
End Sub
Private Sub btnAdd_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnAdd.Click
Dim Row = Me.customerdataset.Purchase_Orders.NewPurchase_OrdersRow
Me.customerdataset.Purchase_Orders.AddPurchase_OrdersRow(Row)
Me.myView.MoveCurrentToLast()
End Sub
Private Sub btnSave_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnSave.Click
Try
If Me.customerdataset.HasChanges Then
Me.customeradapter.Update(Me.customerdataset)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub btnCancel_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnCancel.Click
Me.customerdataset.RejectChanges()
End Sub
Private Sub btnDelete_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnDelete.Click
If Me.myView.CurrentPosition > -1 Then
Dim row = CType(Me.myView.CurrentItem, DataRowView).Row
Me.customerdataset.Purchase_Orders.RemovePurchase_OrdersRow(row)
Me.customerdataset.AcceptChanges()
Me.customeradapter.Update(Me.customerdataset)
End If
End Sub
End Class
cheers.