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

Groups change and IsSelected question

4 Answers 20 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Francisco Amador
Top achievements
Rank 1
Francisco Amador asked on 14 May 2010, 05:15 PM
I'm keeping track of the items that are selected and unselected in the gridview by adding/removing from a list in the SelectionChanged event handler. Unfortunately, when I change the groups it fires a selection changed for each of the items as if they are being unselected. The basic structure of the function I'm using is as follows:

        static void gv_SelectionChanged(object sender, SelectionChangeEventArgs e) 
        { 
            if (changingSelection) 
                return
 
            changingSelection = true
            var gv = e.Source as RadGridView; 
            if (gv != null
            { 
                foreach (CatalogItem addedItem in e.AddedItems) 
                { 
                    //code for adding selection to list 
                } 
 
                foreach (CatalogItem removedItem in e.RemovedItems) 
                { 
                    //code for removing selection from list 
                } 
            } 
            changingSelection = false
        } 

So if an unselect fires for each of the items, then my list will be empty when the groups are changed. The whole purpose of the list was so that I could restore the selections when the grouping was completed.

Is there a way that I could prevent the items from being removed from the list when the groups are changed? A property or something that I could check against in the removal foreach statement?

Thanks in advance

4 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 17 May 2010, 04:14 PM
Hi Francisco Amador,

Could you please provide us with more information about the operation that you are referring to as "change groups". Are you setting new ItemsSource of RadGridView or performing some other operation?

By default, when you group/ungroup selection should not be cleared.


Sincerely yours,
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
Francisco Amador
Top achievements
Rank 1
answered on 17 May 2010, 06:09 PM
I have narrowed down my problem a bit further, and like you said, the selection is not changed when grouping/ungrouping. I do have to change the ItemsSource depending on which column or columns the grid is being grouped by. This is why I want to keep track of what is checked. If the user changes the view of the grid after selecting some items and some of those items are not in the new new source, I want to be able to reselect those items when the user returns to the original view with the original data source.

Now that you mention it though, there does appear to be a different issue related to the change of ItemsSource. The first item of the grid is being selected when the ItemsSource is changed. I know this because the SelectionChanged event is being fired immediately after the ItemsSource is changed. While this does not affect my original problem, I would like to know if it's possible to prevent this selection.

Now back to my original problem. I have narrowed down the problem to filtering. I had not noticed this before because I group and filter in the same function that was modifying the grid. The SelectionChanged event deselects the items that are filtered out (as it probably should). Is there a way to check if the event was fired by user action or any other way around the deselection of items being filtered out? In my grid there may be several items with a specific identifier in different groups and my code selects/deselects all of them if one is selected/deselected. Because of this if one gets filtered out, it is currently deselecting all of them. My list of selected items would also be used to reselect these hidden items if the filter is removed.

Thanks,
Francisco Amador
0
Accepted
Milan
Telerik team
answered on 19 May 2010, 08:01 AM
Hello Francisco Amador,

First item is automatically selected because IsSynchronizedwithCurrent item is set to true by default. If you set this property to false the first item will no longer be selected. 

Unfortunately it is not possible to determine if selection change is caused by user cation or by the API. Also RadGridView cannot reselect previously selected items when a filter is removed but you might be able to implement the such functionality. 

I have attached a sample project which demonstrates how you can preserve selection when RadGridView is paged - this is the same as with filtering. You could try to implement something similar in your application.


All the best,
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
Francisco Amador
Top achievements
Rank 1
answered on 19 May 2010, 02:16 PM
Thank you for your response, the sample project will help me nail down the final details. I already had the SelectGloballySelectedItems style implementation done in my code so I will now just add the boolean for the filtering events and it should work as I am expecting.

Thank you,
Francisco Amador
Tags
GridView
Asked by
Francisco Amador
Top achievements
Rank 1
Answers by
Milan
Telerik team
Francisco Amador
Top achievements
Rank 1
Share this question
or