0

This is my first question and I apologize for my poor background knowledge. I've managed to fake my wake through a lot of C#/WPF/LINQ-to-SQL but I suspect that while I've gotten a lot of things working, I've done a lot of things the "wrong" way. I've Googled myself in circles over this question. My question seems like it should be simple and obvious.

I have two tables represented in my view model.

IQueryable<> Items is the items source for my datagrid. It has a column for CategoryID.

Categories are defined in a separate table with CategoryID and CategoryName.

I'd like to bind my a text column to Item's CategoryID and display the corresponding CategoryName from the Categories table.

I have accomplished it in what I think is the "wrong" way. It seems like there should be a much more straightforward way. I'd like to know whether my implementation is as silly as I think it is, and if so, what's the right way?

Here's my way:

Instead of using a text column, I'm using a (readonly) ComboBox column. I created an ObservableCollection<Category> Categories and I populate from the SQL database. I bind the items source of the ComboBox column to it and bind the selected value to Items and set the DisplayMemberPath to the CategoryName column (from Categories). It works but it just feels wrong!

Thank you!

4

1 回答 1

0

我建议将您的 CategoryName 添加到您的 IQueryable<> Items

于 2012-03-23T13:18:35.463 回答