2

我有一个带有三个控件的 VB winforms 表单,每个控件都显示来自三个相关实体的BindingSource数据(通过s 或绑定的文本框),这些实体是由 DB First 创建的。DataGridView

我需要datagridview显示并允许仅添加/编辑/删除tbl_Distribution_DealerModel_OverAlts与当前tbl_PrimaryDealerGroup记录(加入字段tbl_PrimaryDealerGroup.DealerGroupID = tbl_Distribution_DealerModels_OverAlts.FirstDealerGroupID)和当前tbl_SeriesManufacturer记录(加入两个公共字段:aus_series_cdeManufacturerID)相关的记录。 tbl_Distribution_DealerModel_OverAlts在与其他两个表的关系的多方面:

实体

如何让子实体datagridview仅显示与两个(或更多)父实体记录中的每一个相关的记录?我可能还需要将一个子实体与该项目中的三个或更多父母联系起来,因此一般适用的答案将不胜感激

4

1 回答 1

0

我终于自己解决了这个问题:

Private Sub bs_tblSM_tblPDG_CurrentChanged(sender As System.Object, e As System.EventArgs) Handles bs_tbl_Series_Manufacturer.CurrentChanged, bs_tbl_PrimaryDealerGroup.CurrentChanged
    If bs_tbl_Series_Manufacturer.Current IsNot Nothing And bs_tbl_PrimaryDealerGroup.Current IsNot Nothing Then
        Dim Series As String = bs_tbl_Series_Manufacturer.GetItemProperties(Nothing)("aus_series_cde").GetValue(bs_tbl_Series_Manufacturer.Current)
        Dim Manufacturer As Byte = bs_tbl_Series_Manufacturer.GetItemProperties(Nothing)("ManufacturerID").GetValue(bs_tbl_Series_Manufacturer.Current)
        Dim PDG As Integer = bs_tbl_PrimaryDealerGroup.GetItemProperties(Nothing)("DealerGroupID").GetValue(bs_tbl_PrimaryDealerGroup.Current)
        Dim ChangeFilter As Boolean = False
        If m_CurrentSeries <> Series Then
            m_CurrentSeries = Series
            ChangeFilter = True
        End If
        If m_CurrentManufacturer <> Manufacturer Then
            m_CurrentManufacturer = Manufacturer
            ChangeFilter = True
        End If
        If m_CurrentPDG <> PDG Then
            m_CurrentPDG = PDG
            ChangeFilter = True
        End If
        If ChangeFilter Then
            Dim DlrMdlOverAlts As IEnumerable(Of tbl_Distribution_DealerModel_OverAlts)
            DlrMdlOverAlts = From DDMOA As tbl_Distribution_DealerModel_OverAlts In m_Context.tbl_Distribution_DealerModel_OverAlts.Local.ToBindingList _
                             Where DDMOA.aus_series_cde = m_CurrentSeries And DDMOA.ManufacturerID = m_CurrentManufacturer And DDMOA.FirstDealerGroupID = m_CurrentPDG _
                             Select DDMOA
            bs_tbl_Distribution_DealerModel_OverAlts.DataSource = DlrMdlOverAlts.ToList
            Me.dgvtbcDealerModelOverAlts_aus_series_cde.DefaultCellStyle.NullValue = m_CurrentSeries.ToString
            Me.dgvtbcDealerModelOverAlts_ManufacturerID.DefaultCellStyle.NullValue = m_CurrentManufacturer.ToString
            Me.dgvtbcDealerModelOverAlts_FirstDealerGroupID.DefaultCellStyle.NullValue = m_CurrentPDG.ToString
            bs_tbl_Distribution_DealerModel_OverAlts.ResetBindings(False)
            ChangeFilter = False
        End If
    End If
End Sub

诀窍是不要尝试在 child中使用DataMemberparent s 的 s,而是在两个 parent s中关联代码中的实体。BindingSourceBindingSourceCurrentChangedBindingSource

于 2013-07-31T22:48:45.817 回答