Showing the related data in Datagridview
I have two datatables: Transactions and Accounts.
Transaction has a foreign key IDAccount from Accounts dataTable.
I assign开发者_开发百科 datasource property of Datasource property of Datagridview to Transactions dataTable.
I want to Accounts.description insead of IDAccount in Datagridview.
What must I do?
Make the column in your DataGridView that's bound to the IDAccount field a DataGridViewComboBoxColumn and set its properties as follows:
- DataSource: your Accounts DataTable
- DisplayMember: Description
- ValueMember: IDAccount
The DataGridViewComboBoxColumn
's ValueMember
and DisplayMember
properties allows you to store and manipulate your IDAccount value in your DGV (and data source) while displaying to the user the Description value. The MSDN article I linked explains it well.
精彩评论