Private Sub PaymentDataGrid_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs)
SavePayment()
End Sub
This command autosaves the changes in the details table. The command below autosaves the changes in the masters table.
However, when I am adding a new row in the masters table as well as in the details table, the details table is never related to the master's table. When I debug the studetID after updating the masters table (which is the Identity column), it shows me the the new ID given by the sql server. However in the the details table this Id is always negative. Why is the relation not refreshed as soon as I insert new row in the master's table?
By the way, This problem occurs when I use WPF. I windows forms It seems to work fine.
Look at my code if there is a problem.
Private Sub StudentsDataGrid_RowEditEnding(ByVal sender As Object, ByVal e As System.Windows.Controls.DataGridRowEditEndingEventArgs) Handles StudentsDataGrid.RowEditEnding
Dim item As DataRowView = CType(e.Row.Item, System.Data.DataRowView)
Dim stu As dsMain.StudentsRow = item.Row
Dim row As DataGridRow = e.Row
Dim N_Cell As TextBlock = CType(C_Name.GetCellContent(e.Row), TextBlock)
Dim FN_Cell As TextBlock = CType(C_FName.GetCellContent(e.Row), TextBlock)
Dim GFN_Cell As TextBlock = CType(C_GFName.GetCellContent(e.Row), TextBlock)
Dim RGN_Cell As TextBlock = CType(C_Reg.GetCellContent(e.Row), TextBlock)
Dim STN_Cell As TextBlock = CType(C_Stat.GetCellContent(e.Row), TextBlock)
stu.Name = N_Cell.Text
stu.FathersName = FN_Cell.Text
stu.GrandFathersName = GFN_Cell.Text
stu.Registeredfor = RGN_Cell.Text
stu.Status = STN_Cell.Text
item.EndEdit()
Dim tas As Students.dsMainTableAdapters.StudentsTableAdapter = New Students.dsMainTableAdapters.StudentsTableAdapter()
tas.Update(ds_Main.Students)
Debug.Print(stu.studentID)
Dim cv As BindingListCollectionView
cv = CType(StudentsDataGrid.ItemsSource, BindingListCollectionView)
cv.Refresh()
item.CreateChildView("FK_Payment_Students")
End Sub