This is a migrated thread and some comments may be shown as answers.

[Solved] RIA: GridViewComboBoxColumn throws InvalidOperationException after saving content

1 Answer 138 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Paul Brause
Top achievements
Rank 1
Paul Brause asked on 10 Dec 2009, 10:51 AM
Hi,

I am testing a RadGridView to let a user view and edit an article list via RIA services.

My Entity articles is bound to a DomainDataSource articleSource.

One column in this gridview is a GridViewComboBoxColumn.
This ComboBox is fed by an entity articlegroup in the DomainDataSource articleGroups.
The entity articles is bound to the entity articleGroup via the property ID => articleGroup .ID.

So far everything works, I can view the grid, every ComboBox is filled with all articleGroup entries
and the selected entries are set correctly.

But as soon as I change the selected entry in a  ComboBox and then save the changes by using
articles.SubmitChanges();

I get the error message

The value of key member 'ID' on an instance of an entity of type 'articleGroup ' has changed. Entity key members cannot be changed.

Here is the code for my GridViewComboBoxColumn:


<telerik:GridViewComboBoxColumn  UniqueName="a" Header="a" 
                                 DisplayMemberPath="Caption" 
                                 SelectedValueMemberPath="ID" 
                                 ItemsSourceBinding="{Binding Data, Source={StaticResource articleGroups}}" 
                                 DataMemberBinding="{Binding articleGroup .ID}"/> 

What am I doing wrong? It must be possible to change articleGroup.ID, everything else makes no sense.I must be able to select another articleGroup for an article.

1 Answer, 1 is accepted

Sort by
0
Accepted
Pavel Pavlov
Telerik team
answered on 11 Dec 2009, 02:24 PM
Hello Paul ,

 
It looks more like a problem in way the data model is used  , rather than a problem with RadGridView.

As it would not allow you to change the ID property of the articleGroup , I guess you should work with the articleGroup instance  itself. In this case you will update the articleGroupProperty with  a new instance , rather changing the ID of the existing instance.

Please note that the following combination :

DataMemberBinding="{Binding articleGroup .ID}"
and
SelectedValueMemberPath="ID"
tells the RadGridView to update the ID property of the articleGroup object.

to have it update the whole article instance the syntax would be something like :
DataMemberBinding="{Binding articleGroup }"
and
SelectedValueMemberPath=""


An alternative would be to define the datamodel so  that the Column is bound  directly to the ID property
and not the nested articleGroup.ID property.

In case you still have troubles , just send me your mdf ( or whatever your data file is )  and I will gladly  prepare a working sample.

All the best,
Pavel Pavlov
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Paul Brause
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Share this question
or