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

Multiple selection with data binding in RadGridView

8 Answers 447 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Lars
Top achievements
Rank 1
Lars asked on 12 Aug 2011, 01:53 PM
Hello,

I am trying to implement multiple selection of a RadGridView in an MVVM context with data binding, based on this example.

I have achieved one way of interaction: when the selection state in the grid view is changed, the SelectedItems property of the view model is changed accordingly.

However, when I try to update the view from the viewmodels state, I run into a loop, where a change in the view changes the view model, which tries to update the view again etc. as a consequence, WPF throws an exception, that a change of a collection inside a CollectionChanged event is not possible (which makes sense).

Any ideas how this is solved properly ? Unfortunately, the above mentioned example does not present any further details for this issue.

Lars

8 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 12 Aug 2011, 06:02 PM
Hi Lars,

 I have prepared a sample project in order to show you how the Binding to multiple selection could be implemented. I have one RadGridView and I have added a button to remove one of the items in the SelectedItems collection Property.  By pressing the button you may see that when the Property in the ViewModel has changed, the GridView is updated accordingly.

Please let me know if you have any further problems with the data binding.

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Lars
Top achievements
Rank 1
answered on 22 Aug 2011, 01:33 PM
Hi,

thanks for the sample, that made my day. The solution was much easier than what I tried to build after reading the blog entry mentioned.

This approach should probably go into the documentation for the RadGridView itself.

Lars
0
Dimitrina
Telerik team
answered on 23 Aug 2011, 09:11 AM
Hi Lars,

 Thank you for your feedback. We will consider adding a new 'How To' article into the documentation.
 

Regards,
Didie
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Renier Pretorius
Top achievements
Rank 1
answered on 06 Jun 2012, 01:56 AM
Hi Didie,

I have followed your example but since I am using the MVVMLight toolkit I do not explicitly bind my view model in the view as the data context but relay on the ViewModelLocator to do that. It appears as if the OnAttached event fires before the this completes as I get a NullReferenceException on the this.AssociatedObject.DataContext part. Any ideas how to resolve other that  explicitly binding the data context?
0
Markus
Top achievements
Rank 2
answered on 30 Nov 2012, 10:42 AM
Hi
Good Question, i have the same Problem

Any Solutions?

Regards Markus
0
Heike
Top achievements
Rank 1
answered on 29 May 2015, 09:11 AM

Hi, Dimitrina!

I used your solution to keep the SelectedItems colleciton in sync with my ViewModels property, and it works, as far as the collection is concerned.

But changing the selection in the ViewModel (first clearing the collection and then adding items) does not produce the expected visual result. The SelectedItems colleciton of the GridView is correct, but sometimes only the first item is highlighted.

Maybe it is because I am creating new Items, adding them to the collection which ist bound as ItemsSource and then add them to the SelectedItems. But once again: the SelectedItems collection is always correct, in the ViewModel and in the GridView. It is just the visual feedback, which is not as expected.

Any ideas what is going wrong?

Kind regards,
Heike

 

0
Dimitrina
Telerik team
answered on 29 May 2015, 12:14 PM
Hi Heike,

You can check this github example on how to bind the SelectedItems to a collection from your view model
Although GitHub is a very well-known platform we saw a better and easier approach for reviewing our examples developing our brand new SDK Samples Browser. You can also use it to review the examples.

I hope this approach will work for you. 

Regards,
Dimitrina
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Zahra
Top achievements
Rank 1
answered on 20 May 2019, 01:01 PM

when using multiple binding in WPF on two property that merge in one column  binding searh dose not work 

 

please give me a solution

Tags
GridView
Asked by
Lars
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Lars
Top achievements
Rank 1
Renier Pretorius
Top achievements
Rank 1
Markus
Top achievements
Rank 2
Heike
Top achievements
Rank 1
Zahra
Top achievements
Rank 1
Share this question
or