Unable to set DataGridComboBoxColumn to Entity framework Navigation Property values.

Nov 12, 2009 at 11:48 AM
Edited Nov 12, 2009 at 11:50 AM
    <tk:DataGrid AutoGenerateColumns="False" Name="dgItems" ItemsSource="{Binding}">
        <tk:DataGrid.Columns>

            <!--Works-->
            <tk:DataGridComboBoxColumn 
                Header="Group" 
                DisplayMemberPath="Title"
                SelectedValuePath="GroupId"
                SelectedValueBinding="{Binding Group.GroupId}"
                ItemsSource="{Binding Context.GroupsList, Source={x:Static Application.Current}}"/> 

           
            <!--This works great-->
            <tk:DataGridTextColumn Binding="{Binding Group.Category.Title}" Header="Cat"/>
            
            <!--This doesn't work, The items are shown in the list but the value isn't selected (eventho it's actually bound just like the above text col). -->
            <tk:DataGridComboBoxColumn                                        
                Header="Categroy" 
                DisplayMemberPath="Title"
                SelectedValueBinding="{Binding Group.Category.CategoryId}"
                ItemsSource="{Binding Context.CategoriesList, Source={x:Static Application.Current}}"/>
         
    </tk:DataGrid>


Nov 12, 2009 at 11:57 AM

The problem was I didn't set the SelectedValuePath property.

Jan 6, 2010 at 10:59 AM

Hi,

I have a similar problem, everything works correctly (the right item is selected in the drop down on load etc) until I drop down and select a new item in the list, the selection works fine but as soon as I move away from the field it reverts back to the original value. I tried adding in two way binding, but this did not seem to do the trick. Any ideas?

  <toolkit:DataGridComboBoxColumn
                                           DisplayMemberPath="Name"
                                           SelectedValuePath="Id"    
                                           SelectedValueBinding="{Binding Customer.Id, Mode=TwoWay}"          
                                           Header="Customer HDR"
                                           ItemsSource="{Binding Source={StaticResource customerDataProvider}}">
                </toolkit:DataGridComboBoxColumn>

Jan 6, 2010 at 11:54 AM
Edited Jan 6, 2010 at 11:58 AM

Is the value selected correctly as well?
i.e. if the correct value from the object is selected in the Combobox.
What I mean to ask is, you're sure it's bound to your object?
If you use EF make sure the Customer property is loaded and not null.

Try to use SelectedItemBinding and set it to the customer object itself (e.g. SelectedItemBinding="{Binding Customer}", you can delete the Value fields.

Good luck.

Jan 6, 2010 at 2:36 PM
Hi,

Thanks for the reply - I tried the SelectedItemBinding with no joy.
Can you tell me how your ItemSource on your DataGridComboBoxColumn
looks (the XAML and the object / code referenced)? I am currently
using an ObjectDataSource and I think that may be a problem.

I did initially have the customer not populated (that one took me a
while to find!) but then added an include to sort it out:

uiDgProject.ItemsSource =
(IEnumerable<Project>)servicesModel.Project.Include("Customer").OrderBy(orderBy);

On 1/6/10, weitzhandler <notifications@codeplex.com> wrote:
> From: weitzhandler
>
> Is the value selected correctly as well?
> i.e. if the correct value from the object is selected in the Combobox.
> What I mean to ask is, you're sure it's bound to your object?
> If you use EF make sure the Customer property is loaded and not null.Try to
> use SelectedItemBinding and set it to the customer object itself (e.g.
> SelectedItemBinding="{Binding Customer}".Good luck.
>
>