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

Databinding to SelectedItems property of the GridView

8 Answers 216 Views
GridView
This is a migrated thread and some comments may be shown as answers.
David Sandor
Top achievements
Rank 1
David Sandor asked on 04 Jun 2010, 06:04 PM
It seems impossible even though I am using a binding mode of OneWayToSource.  Are there plans to allow us to Databaing to this property.  It would be great to be able to Databind that to a collection on my viewmodel.

Thanks,
David Sandor

8 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 09 Jun 2010, 07:31 AM
Hi David Sandor,

Could you please take a look at this blog post.


Regards,
Milan
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
0
David Sandor
Top achievements
Rank 1
answered on 09 Jun 2010, 01:24 PM
Hi Milan,

That blog post does in fact address this issue.  I do feel though that the blog post is really making something that should be simple into a very complicated mess.  Using behaviors is really neat but I treat the GridView as my data provider and I expect standard behavior of the Grid to allow me to use standard databinging techniques to accomplish my goals.  Having to create a Bahavior is a hack.

If I am going to go through the trouble of creating a hack for this problem I would rather add a 1 liner of code behind to accomplish the same:

private void RadGridView_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangeEventArgs e)  
{  
    viewModel.SetSelectedItems(((RadGridView)sender).SelectedItems);  

SetSelectedItems basically adding to an ObservableCollection<> everything in .SelectedItems.

Thanks for the help, but I would love to see the SelectedItems a bindable property unless there is some really good reason for it not to be bindable.

David Sandor
0
Vlad
Telerik team
answered on 09 Jun 2010, 01:39 PM
Hello David,

 SelectedItems is bindable however you cannot use TwoWay binding since the property is read-only. This is exactly the same as any standard Silverlight component with multiple selection.

Kind regards,
Vlad
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
0
David Sandor
Top achievements
Rank 1
answered on 09 Jun 2010, 04:17 PM
Hi Vlad,

Thanks for your response.  I am not sure if it matters, but I am using the WPF version.  If you read my original post on this topic and google around a bit you will note that you can not actually databind to that property.  As I stated earlier, it does not even work with OneWayToSource binding.  Please prove me wrong :)  I would love for that to work.

Thanks,
David Sandor
0
Vlad
Telerik team
answered on 10 Jun 2010, 07:24 AM
Hi David,

 Sorry for the Silverlight confusion!

The idea was to point that there is no Silverlight and/or WPF component with multiple selection read/write property. As to the binding you can check our "Selection" example - ListBox on the right is bound SelectedItems.

If you know any component (ItemsControl, ListBox, etc.) with "SelectedItems" property with setter please post it!

Regards,
Vlad
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
0
Steve
Top achievements
Rank 1
answered on 21 Oct 2016, 08:49 AM

6 years later.... RadAutoCompleteBox has this!

Does that mean you can implement it in RadGridView now? :-)

0
Martin
Telerik team
answered on 26 Oct 2016, 07:57 AM
Hello Steve,

I do understand your point regarding the SelectedItems property of RadAutoCompleteBox, however, the architecture of the selection functionality of RadGridView is designed in such manner, that its SelectedItems property should be left to be read-only. 
As already mentioned in the forum the SelectedItems property is bindable but only using OneWay binding as is presented in our "Selection" example.

Regards,
Martin Vatev
Telerik by Progress
Do you need help with upgrading your WPF project? Try the Telerik API Analyzer and share your thoughts!
0
Carmen
Top achievements
Rank 1
answered on 09 Aug 2017, 08:16 AM
can you please show me how you instantiate the viewModel in code behind?
Tags
GridView
Asked by
David Sandor
Top achievements
Rank 1
Answers by
Milan
Telerik team
David Sandor
Top achievements
Rank 1
Vlad
Telerik team
Steve
Top achievements
Rank 1
Martin
Telerik team
Carmen
Top achievements
Rank 1
Share this question
or