我有一个带有三个BindingSource
控件的VB winforms表单,每个控件都显示来自三个创建了DB First的相关实体的数据(通过DataGridView
s或绑定文本框)。
我需要datagridview
显示&仅允许添加/编辑/删除与当前tbl_Distribution_DealerModel_OverAlts
记录(加入字段tbl_PrimaryDealerGroup
)和当前tbl_PrimaryDealerGroup.DealerGroupID = tbl_Distribution_DealerModels_OverAlts.FirstDealerGroupID
记录相关的tbl_SeriesManufacturer
条记录(加入两个常见记录)字段:aus_series_cde
和ManufacturerID
)。 tbl_Distribution_DealerModel_OverAlts
与其他两个表的关系在很多方面:
如何让子实体的datagridview
仅显示与两个(或更多)父实体记录中的每一个相关的记录?我可能还需要在这个项目中将儿童实体与三个或更多的父母联系起来,因此一般适用的答案将不胜感激
答案 0 :(得分: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
诀窍是不要尝试在子DataMember
中使用BindingSource
个父BindingSource
个},而是将两个CurrentChanged
中代码中的实体关联起来父BindingSource
s。