SelectedRecord MVVM problem

6 posts, 0 answers
  1. Alexey
    Alexey avatar
    79 posts
    Member since:
    Oct 2008

    Posted 04 Jun 2009 Link to this post

    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.
  2. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 05 Jun 2009 Link to this post

    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.
  3. DevCraft banner
  4. Alexey
    Alexey avatar
    79 posts
    Member since:
    Oct 2008

    Posted 05 Jun 2009 Link to this post

    =( That is bad. Are you planning to create 100% MVVM frendly controls in future?
  5. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 09 Jun 2009 Link to this post

    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.
  6. Alexey
    Alexey avatar
    79 posts
    Member since:
    Oct 2008

    Posted 09 Jun 2009 Link to this post

    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.
  7. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 09 Jun 2009 Link to this post

    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.
Back to Top
DevCraft banner