Hi,
small question: how can I databind SelectedItems of a gridview to a collection of my viewmodel? I have a gridview with SelectionMode set to Extended:
Kind regards,
L
small question: how can I databind SelectedItems of a gridview to a collection of my viewmodel? I have a gridview with SelectionMode set to Extended:
<
telerik:RadGridView
Name
=
"patientsGridView"
SelectionMode
=
"Extended"
ItemsSource
=
"{Binding Patients}"
SelectedItem
=
"{Binding SelectedPatient}"
AutoGenerateColumns
=
"False"
IsReadOnly
=
"True"
>
and the viewmodel would contain:
But how can I bind the grid's SelectedItems to the viewmodel's SelectedPatients?
Thanks,public
ObservableCollection<PatientViewModel> SelectedPatients { ... }
But how can I bind the grid's SelectedItems to the viewmodel's SelectedPatients?
Kind regards,
L
6 Answers, 1 is accepted
0
Hi,
Vlad
the Telerik team
You can check this blog post for more info.
Greetings,Vlad
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Ludwig
Top achievements
Rank 1
answered on 07 Mar 2011, 04:44 PM
I tried it, but how can I get notified when the selection changes (without using code behind)?
0
Ted
Top achievements
Rank 1
answered on 15 May 2014, 12:56 AM
The correct link to the blog post:
How To: Synchronize your UI selected items with your data context using MVVM and Blend behaviors for Silverlight and WPF
How To: Synchronize your UI selected items with your data context using MVVM and Blend behaviors for Silverlight and WPF
0
Brennan
Top achievements
Rank 1
answered on 07 Oct 2016, 08:29 PM
I'm curiou as to why people keep posting this blog as an answer. It doesn't work at all.
0
Hello Brennan,
For brevity, only part of the full code has been included in the blog post. A working version, however, has been provided at the bottom of the post. For your convenience, I'm attaching it here as well.
You can also find a similar example in the SDK Samples Browser with the title Binding SelectedItems From ViewModel.
I hope you find this helpful. Do let me know if you have any other questions or concerns.
Regards,
Dilyan Traykov
Telerik by Progress
For brevity, only part of the full code has been included in the blog post. A working version, however, has been provided at the bottom of the post. For your convenience, I'm attaching it here as well.
You can also find a similar example in the SDK Samples Browser with the title Binding SelectedItems From ViewModel.
Regards,
Dilyan Traykov
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Brennan
Top achievements
Rank 1
answered on 11 Oct 2016, 01:54 PM
Hi Dilyan,
I was actually using the full code example on the blog post and still could not get it to work. The github SDK example, however, I was able to get working, once I realized the view model SelectedItems property does not have a setter. I was trying to two-way bind the setter, and was expecting my viewmodel to be updated right as the selection in the grid changed, which obviously would not work in this case. Once I explicitly called the getter on my viewmodel selecteditems collection, I got the expected result.
Thanks,
Pradeep
commented on 25 Nov 2021, 01:09 PM
Top achievements
Rank 1
Hi Brennan,
What do you mean by "Once I explicitly called the getter on my viewmodel selecteditems collection, I got the expected result." Please explain.
I am trying the two way binding of SelectedItems collection of my viewmodel. Thanks.
What do you mean by "Once I explicitly called the getter on my viewmodel selecteditems collection, I got the expected result." Please explain.
I am trying the two way binding of SelectedItems collection of my viewmodel. Thanks.