views:

35

answers:

2

Hello,

I have a DataGrid with ItemsSource set to a list of products and I have a DataGridComboBoxColumn inside the DataGrid with ItemsSource set to a list of categories. That way I want the user to choose a certain category for each product.

I always get the binding error:

BindingExpression path error: 'Categories' property not found on 'object' ''Product' (Hash)

Well I do not want to make the Category list part of the Product entity as 1:N relation, although it would work that way.

I want to keep them separate.

Anyone knows a workaround?

+1  A: 

Create class with static property like

static class ValueLists
{
   public static IEnumerable<Category> Categories {get {... }}
}

and use following binding

ItemsSource="{x:Static myNs:ValueList.Categories}" />
STO
I found a good link dealing with exactly the same stuff I need:http://stackoverflow.com/questions/1633800/wpf-datagrid-datagridcomboxbox-itemssource-binding-to-a-collection-of-collection
msfanboy
I can not implement INotifyPropertChanged in static class what I need ;-)instead of static binding wouldnt that work ? =>ItemsSource="{Binding Path=DataContext.Categories, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" IsReadOnly="True" Background="White" />
msfanboy
A: 

This is probably relevant to your problem.

What is happening here?
The Columns collection is just a property in the Datagrid; this collection is not in the logical (or visual) tree, therefore the DataContext is not being inherited, which leads to there being nothing to bind to.

ArildF