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

SelectedRecord MVVM problem

5 Answers 228 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Alexey
Top achievements
Rank 2
Alexey asked on 04 Jun 2009, 01:18 PM
Hi guys!

I've got a problem with databinding of SelectedRecords property of RadGridView.

In my application I'm using MVVM pattern. So I need to bind ViewModel selectedItems to SelectedRecords of RadGridView to notify my ViewModel about selection changes (I'm using multiple selection).

When I'm trying to bind SelectedRecords property my browsers shutdowns (both IE and Mozilla).

Best regards,
Alexey Zakharov.

5 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 05 Jun 2009, 09:02 AM
Hi Alexey,

SelectedRecords is collection property with get only access. This is why you cannot bind it (it cannot be assigned). You should attach handler to SelectionChanged event and synchronize it with your SelectedItems collection.

Let us know if you need more information.

Greetings,
Hristo
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Alexey
Top achievements
Rank 2
answered on 05 Jun 2009, 05:33 PM
=( That is bad. Are you planning to create 100% MVVM frendly controls in future?
0
Milan
Telerik team
answered on 09 Jun 2009, 06:48 AM
Hello Alexey,

In case you would like your ViewModel to be notified of any selection changes there should be no problem binding your ViewModel's selected records to RadGridView.SelectedRecords collection. For example, there is no problem to display the selected items in a ListView control - the binding looks like that:

Binding binding = new Binding("SelectedRecords");  
binding.Mode = BindingMode.OneWay;  
binding.Source = this.RadGridView1;  
this.view.SetBinding(ListView.ItemsSourceProperty, binding); 

Unfortunately it is impossible to update the RadGridView.SelectedRecords collection through a similar TwoWay binding. I am affraid that such scenarios are not supported by any ItemsControl, even in WPF.

In case you are having troubles with the first scenario you can send us more info like any error messages, etc so that we can help you solve the problem.

Sincerely yours,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Alexey
Top achievements
Rank 2
answered on 09 Jun 2009, 10:25 AM
I've solved the problem using command behavior pattern. Currently we use DataGrid, but it should work for RadTreeView too. Here is the link to the post where I have described solution.
0
Milan
Telerik team
answered on 09 Jun 2009, 10:58 AM
Hi Alexey,

Thanks for sharing your solution on our forums.

Best wishes,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Alexey
Top achievements
Rank 2
Answers by
Hristo
Telerik team
Alexey
Top achievements
Rank 2
Milan
Telerik team
Share this question
or