WPF DataGrid Lookup Column Value
I have a DataGrid bound to a table in DataSet A. I'm manually creating the grid columns.
Two of the columns comprise the key into a table in DataSet B and I need to display the (read-only) lookup Name instead of the IDs.
I'm guessing I use a Value Converter of some sort but don't know how to get started.
I saw this: Lookup-id-control in WPF 开发者_StackOverflowDataGrid but 1) I need to specify the combobox's ItemSource in the code and can't figure out how to do so 2) I've got a tuple key 3) it seems there should a more straightforward way to accomplish this.
Thanks! Dan
It hurts that the tables are in different DataSet
s. Can you possibly clone the referenced table into DataSet
A?
If they were in the same DataSet
, then it would be simple:
Create a
DataRelation
between the child table (the one with the foreign key columns) and the parent table (the one containing the lookup name).Create a
DataColumn
in the child table and set itsExpression
toParent!Name
.Add the new
DataColumn
to yourDataGrid
.
As I said in my comment, I'm falling back on Plan A which is more model/view friendly.
I think I'm just going about it 'wrong' otherwise.
精彩评论