开发者

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 DataSets. Can you possibly clone the referenced table into DataSet A?

If they were in the same DataSet, then it would be simple:

  1. Create a DataRelation between the child table (the one with the foreign key columns) and the parent table (the one containing the lookup name).

  2. Create a DataColumn in the child table and set its Expression to Parent!Name.

  3. Add the new DataColumn to your DataGrid.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜