Quantcast
Viewing all articles
Browse latest Browse all 18858

EF4 and WPF data binding - many to many relationship

Thanks in advance.

Without boring you to death with all the details - I have an EF model intended to track project requests. The hierarchy is that corporate divisions have departments; the departments submit project requests. The requests have to be categorized by risk and can fall into one or more categories. This last component is represented in the database via a Many-to-Many table incorporating the RequestIDs and the RiskIDs. EF eliminates the many-to-many table and shows the association between the Request and RiskCategory entities.

I've created a WPF form that ALMOST works they way I want, showing the users the details of their requests. I'd like to add to the form a combobox within a listview, from which the users can select the categories that apply to a given request. Only the combobox will be in the ListView

So..the CollectionViewSource for the RiskCategories table is categoriesViewSource, and the CollectionViewSource for the RequestItems is named
RequestItemsRiskCategoriesViewSource

The Datacontext of the ListView itself is set to RequestItemsRiskCategoriesViewSource, and the combobox's ItemsSource is set to the categoriesViewSource. Try as I might, I can only get the combox to display the available RiskCategories, not the ones already assigned to the current RequestItem. If there is one category assigned, then one combobox hows in the listview. If 3, then 3 comboxes appear. But each one displays the first category in the list, not the assigned categories.

Changing the datatemplate to a Textbox bound to Category works just fine, but gives the user no way to choose a valid value

Here's the XAML that doesn't work

<ListView.View><GridView><GridViewColumnx:Name="categoryColumn"Header="Category"Width="80"><GridViewColumn.CellTemplate><DataTemplate><ComboBoxItemsSource="{Binding Source={StaticResource categoriesViewSource}}"SelectedValue="{Binding Path=RiskCategory}"DisplayMemberPath="Category"></ComboBox></DataTemplate></GridViewColumn.CellTemplate></GridViewColumn></GridView></ListView.View>

So...how do I get this comobox to work?


Viewing all articles
Browse latest Browse all 18858

Trending Articles