Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
VB
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.

VB
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
Posted

1 solution

http://msdn.microsoft.com/en-us/vcsharp/Video/dd239277
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900