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

[Solved] Combobox Error

2 Answers 97 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.
Heather
Top achievements
Rank 1
Heather asked on 21 Sep 2009, 07:29 PM
I am using 2009.2.911.1030 and MVVM pattern with wcf services for data retrieval.

I have a ViewModel with a WorkOrder object.  The WorkOrder has an ObservableCollection(Of WorkItem).  Each WorkItem has a WorkTypeId.  The ViewModel also has an ObservableCollection(Of WorkType) exposed through a WorkTypeList property.  The DataContext of the usercontrol is set to my viewmodel.  I want to display a grid of WorkItems and show a dropdown list of WorkTypes for each WorkItem row.  Here is the xaml for my grid:

 

 

<telerikGridView:RadGridView x:Name="itemsgrid" AutoGenerateColumns="False" CanUserFreezeColumns="False" CanUserReorderColumns="False" ShowGroupPanel="False" ItemsSource="{Binding WorkOrder.WorkItems, Mode=OneWay}" IsFilteringAllowed="False" >

 

 

<telerikGridView:RadGridView.Columns>

 

 

 

<telerikGridView:GridViewComboBoxColumn HeaderText="Work Type" Width="*" DisplayMemberPath="Name" SelectedValueMemberPath="Id" UniqueName="WorkTypeId" DataMemberPath="WorkTypeId"/>

 

 

</telerikGridView:RadGridView.Columns>

In code behind in the UserControl loaded event:
CType(itemsgrid.Columns(0), GridViewComboBoxColumn).ItemsSource 
        =
CType(Me.DataContext, WorkOrderEditViewModel).WorkTypeList

I have a few issues:

 

 

 

1.  If I manually create an observable collection of WorkType objects and assign it in place of the WorkTypeList property, the grid shows with correct WorkType selected but when I click on the cell to go into edit mode I get an unhandled error:  An item with the same key has already been added.
2.  If I use the WorkTypeList property which is filled async via a wcf service, the selected worktype does not appear and I get the same "already added" error when I click on the cell to go into edit mode.

I tried switching to using a GridViewDataColumn and setting the EditorSettings in code behind without any additional luck.

Please advise,

Heather

2 Answers, 1 is accepted

Sort by
0
Heather
Top achievements
Rank 1
answered on 21 Sep 2009, 08:25 PM
OK, so after playing around with a simple test case outside of my main application I got it to work.  I went back into my main application and switched it so the UniqueName and DataMemberPath were specified in the xaml before the SelectedValuePath and DisplayMemberPath....now it works, kind of.  I no longer get the "already been added" exception which is good.  Does this make sense???

Now my problem is due to the async nature of getting my data back.  If my lookup list comes back quickly, the correct value is selected in the grid and everything looks OK.  If it takes a few moments for the data for my lookup list to return my grid does not show the selected value until I click in the cell to enter edit mode and then the correct item is selected.  How do we tell the Grid's combobox to refresh itself in a MVVM scenario?  My viewmodel knows nothing of my view.  If I could bind in XAML I assume the combo would know that the observablecollection was modified and update accordingly but it does not seem to work with the need to set the itemsource in codebehind.

0
Pavel Pavlov
Telerik team
answered on 24 Sep 2009, 11:58 AM

Hello Heather,

Please try using the DataMemberBinding property of the column instead of DataMemberPath.

Something like :

DataMemberBinding = {Binding WorkTypeId, Mode=TwoWay}


instead of:

DataMemberPath="WorkTypeId"

In case this does not help , please send me the implementation (vb code) of the WorkType and the WorkItem classes and I will try to provide a working sample.  Ideally if I have your project, I may revise it to see what causes the trouble and find a solution or a fix.  (To be able to send/attach files you will need open a support ticket as attachments are not supported in the forum) .

Regards,

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
Heather
Top achievements
Rank 1
Answers by
Heather
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Share this question
or