2013-07-22 75 views
2

我有一個帶有三個BindingSource控件的VB winforms表單,每個控件都顯示來自創建DB First的三個相關實體的數據(通過DataGridView s或綁定文本框)。在與多個父實體記錄相關的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是對關係的許多方其他兩個表:

Entities

我怎麼能有一個孩子實體的datagridview只顯示有多個相關的兩個(或多個)父實體記錄記錄?它也可能有必要對我來說,這個項目涉及子實體三個或三個以上的父母,所以一般適用的答案,將不勝感激

回答

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 

訣竅是不要嘗試在子BindingSource中使用父代BindingSourceDataMember s,而是將代碼中的實體與父代BindingSourceCurrentChanged中的代碼相關聯。

相關問題