Multiselect Binding in RadGridView

10 posts, 0 answers
  1. Yaniv Perry
    Yaniv Perry avatar
    3 posts
    Member since:
    Feb 2010

    Posted 30 May 2010 Link to this post

    Hello,

    I am trying to implement MVVM pattern using RadGridView.
    I have a People property as the ItemsSource of the Grid.
    Now, I also have a SelectedPeople property that I want to bind to the grid (Two Way).
    Anyone knows how can that be supported in RagGridView?

    Thanks!
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 31 May 2010 Link to this post

    Hi,

    Since SelectedItems property of the grid is read-only similar to all UI components with multiple selection you will need custom attached behavior to keep both collection synchronized. You can use Blend behaviors similar for example to this blog post or write your own similar to some of our demos (we have problems with additional files in our WPF demos code viewer - please check the Silverlight version for more info).

    All the best,
    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.
  3. Yaniv Perry
    Yaniv Perry avatar
    3 posts
    Member since:
    Feb 2010

    Posted 31 May 2010 Link to this post

    Hi,

    Thanks for you reply.
    Are you sure the link "Empty data template in RadGridView for Silverlight (and WPF) " is relevant to my question?
  4. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 31 May 2010 Link to this post

    Hi,

    Yes! You can check the demo project to know more on how to create Blend behavior.

    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.
  5. Yaniv Perry
    Yaniv Perry avatar
    3 posts
    Member since:
    Feb 2010

    Posted 31 May 2010 Link to this post

    Hi again,

    Downloaded the project, but it does not seem to run (not supported in my studio version)
    Any chance you show me the main idea of binding to multiselection in your GridView within a simple straight forward sample?

    Thanks a lot!
  6. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 31 May 2010 Link to this post

    Hello,

    You do not need to run the project to check the idea behind Blend behaviors - you can create also your own behavior similar to the demo posted in my previous reply. My idea was to show you how to create your own behavior (Blend style or custom) to synchronize both collections (SelectedItems and your own property). For example if you choose Blend behaviors you need to create something like this:

    public class MyMultiSelectBehavior : Behavior<RadGridView>
        {
            protected override void OnAttached()
            {
                base.OnAttached();

                Grid.SelectedItems.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(SelectedItems_CollectionChanged);
            }

            void SelectedItems_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
            {
                throw new NotImplementedException();
            }

            public RadGridView Grid
            {
                get
                {
                    return AssociatedObject as RadGridView;
                }
            }
        }

    Please check the project again to know more about how to attach this behavior to desired grid declaration in XAML.

    Best wishes,
    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.
  7. Aleksey
    Aleksey avatar
    13 posts
    Member since:
    Nov 2012

    Posted 16 May 2014 Link to this post

    Can such behavior cause memory leak?
    I think in my case it is.
  8. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 16 May 2014 Link to this post

    Hello,

    Such a behavior should not leak.

    What are your concerns for leaking? Is there anything else that can be causing it?

    Regards,
    Didie
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  9. Aleksey
    Aleksey avatar
    13 posts
    Member since:
    Nov 2012

    Posted 17 May 2014 Link to this post

    Hello.
    I'm used such behavior in RadGridView placed in TabControl with IsContentPreserved="True" ( http://www.telerik.com/forums/memory-leaks-with-iscontentpreserved-and-remove-from-mvvm-binded-itemsource#fkGdJiUHXUCQ9vKZvav-aw ). When tab is deleted from ItemSource GC cannot collect it cause it have event listeners to both View and ViewModel collection with closure to this behavior and foreign collection.
    To fix it I create two fields in behavior to hold CollectionChangeHandler. And OnAttach and DependencyPropertyChanged fill it with same methods but with WeakReference on foreign collection. And subscribe to it. And memory leak leaks.
  10. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 21 May 2014 Link to this post

    Hello,

    We are not aware of such leaks with RadGridview. Does it also leak when you replace it with MS DataGrid? If no, then is there a problem without the TabControl? Are you testing with the latest version?

    If it does leak with our control, may I ask you to isolate the issue in a demo project and send it to us. You can take a look at this blog post for a reference on how to isolate an issue. You can open a support ticket and attach the project there. 

    Regards,
    Didie
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top