0
我正在開發一個Windows應用程序。我只想概括所有主表單的代碼。所以我決定用特定的容器創建一個用戶控件。我們正在使用LINQ to SQL,我想傳遞一個表名並獲取相應的數據。我有一個BindingSource和一個BindingNavigator以及一個DataGridView。我使用下面的代碼:通過LINQ To SQL動態生成表。如何將ITable更改爲表?
Dim t As Type = objDB.GetType()
Dim p As PropertyInfo = t.GetProperty(value)
Dim table = CType(p.GetValue(objDB, Nothing), ITable)
dgvMaster.DataSource = table 'attaching the table as datasource to datagrid works
BSMaster.DataSource = table 'trying to attach the datasource to binding source fails
它只需要弄清楚如何將它綁定到綁定源,我完成了。任何想法或在這方面的幫助非常感謝。
感謝,
拉賈
問題是BS Master在分配ITable時沒有得到任何數據。如果我指定確切的類,它確實很好。例如。 objDB.Categories。這就是爲什麼我想將ITable更改爲Table Of(Of Categories)。 – Raja 2010-02-17 16:13:54
如果BSMaster不包含任何數據,則會出現此行爲。 BindingSource會嘗試從表中創建一些列,失敗並在此之後不會再嘗試重新創建列。 您可以手動創建列或傳遞要創建的列的類型。 – Devart 2010-02-23 14:58:45