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

Multiselect Binding in RadGridView

9 Answers 380 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Yaniv Perry
Top achievements
Rank 1
Yaniv Perry asked on 30 May 2010, 08:48 AM
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!

9 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 31 May 2010, 07:39 AM
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.
0
Yaniv Perry
Top achievements
Rank 1
answered on 31 May 2010, 08:23 AM
Hi,

Thanks for you reply.
Are you sure the link "Empty data template in RadGridView for Silverlight (and WPF) " is relevant to my question?
0
Vlad
Telerik team
answered on 31 May 2010, 08:24 AM
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.
0
Yaniv Perry
Top achievements
Rank 1
answered on 31 May 2010, 08:39 AM
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!
0
Vlad
Telerik team
answered on 31 May 2010, 09:00 AM
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.
0
Aleksey
Top achievements
Rank 1
answered on 16 May 2014, 09:08 AM
Can such behavior cause memory leak?
I think in my case it is.
0
Dimitrina
Telerik team
answered on 16 May 2014, 02:07 PM
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.
 
0
Aleksey
Top achievements
Rank 1
answered on 17 May 2014, 09:19 AM
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.
0
Dimitrina
Telerik team
answered on 21 May 2014, 11:18 AM
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.
 
Tags
GridView
Asked by
Yaniv Perry
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Yaniv Perry
Top achievements
Rank 1
Aleksey
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or