本文介绍了WPF中的主从关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Private Sub PaymentDataGrid_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs)
    SavePayment()
End Sub



此命令将自动保存详细信息表中的更改.下面的命令自动保存masters表中的更改.

但是,当我在masters表以及detail表中添加新行时,Details表从不与master表相关.当我在更新masters表(这是Identity列)之后调试studetID时,它向我显示了sql server给定的新ID.但是,在详细信息表中,此ID始终为负.为什么在主表中插入新行后关系就不会刷新?

顺便说一句,当我使用WPF时,会发生此问题.我在Windows窗体上似乎工作正常.

看看我的代码是否有问题.



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

推荐答案


这篇关于WPF中的主从关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 15:19