2011-04-15 80 views
1

我有兩個數據表:事務和帳戶。顯示Datagridview中的相關數據

事務從帳戶dataTable中有一個外鍵IDAccount。

我將Datagridview的Datasource屬性的datasource屬性分配給Transactions dataTable。

我想在Datagridview中使用IDAccount的Accounts.description insead。

我該做什麼?

回答

2

做一個綁定到IDAccount領域DataGridViewComboBoxColumn在您的DataGridView列,並如下設置其屬性:

  • 數據源:您的帳戶的DataTable
  • DisplayMember:說明
  • ValueMember:IDAccount

DataGridViewComboBoxColumnValueMemberDisplayMember屬性允許你sto在向用戶顯示描述值時,在您的DGV(和數據源)中重新操作您的IDAccount值。我鏈接的MSDN文章很好地解釋了它。

+1

+1優秀的答案!另外,他們可能希望將DisplayStyle屬性設置爲「Nothing」,以便下拉按鈕不顯示在列上。 – Ken 2011-04-15 15:44:01