This is a migrated thread and some comments may be shown as answers.
Reverse RadGridView selection
18 Answers 120 Views
This is a migrated thread and some comments may be shown as answers.
simeon
Top achievements
Rank 1
simeon asked on 17 Aug 2009, 01:33 PM
I am currently writing a method to reverse the selected rows in the RadGridView.  My code looks like this

private

 

void RadMenuItemReverseSelection_Click(object sender, RoutedEventArgs e)

 

{

    System.Collections.ObjectModel.

 

ObservableCollection<object> savedSelectedItems = DataGridList.SelectedItems;

 

    DataGridList.SelectedItems.Clear();

    DataGridList.CurrentItem =

 

null;

 

 

 

    foreach (object o in (System.Collections.ObjectModel.ObservableCollection<Site>) DataGridList.ItemsSource)

 

    {

 

 

        if (savedSelectedItems.Contains(o) == false) DataGridList.SelectedItems.Add(o);

 

    }

 

 

 

    if (DataGridList.SelectedItems.Count != 0) DataGridList.CurrentItem = DataGridList.SelectedItems[0];

 

}

But when we are adding the items to the selected items in the for loop its becomes very slow.  (It actually hangs the UI on me test page as there are about 5000 rows to select.)  The SelectAll and SelectNone methods on the grid are a lot quicker though (even with the 5000 of rows).  So I was wondering is there a way to load the selected items collection quickly?

On a side note is it possible to display the Asynchronus animation from a call in the code behind.  As I would quite like to display the working message when I am waiting of the data being returned from the service call and when we invert the selection.

Cheers,

Simeon

 

18 Answers, 1 is accepted

Sort by
0
Accepted
Milan
Telerik team
answered on 19 Aug 2009, 09:12 AM
Hello simeon,

You could utilize the UnselectAll and SelectAll methods to boost the performance when reverting the selection. Here is a workaround that you can try:

private void Button_Click(object sender, System.Windows.RoutedEventArgs e)  
{  
    this.playersGrid.IsBusy = true;  
    this.ReverseSelection();  
    this.playersGrid.IsBusy = false;  
}  
 
private void ReverseSelection()  
{  
    if (this.playersGrid.SelectedItems.Count <= this.playersGrid.Items.Count)  
        this.ReverseWithSelectAll();  
    else 
        ReverseWithUnselectAll();  
}  
 
private void ReverseWithUnselectAll()  
{  
    var oldSelectedItems = this.playersGrid.SelectedItems.ToList();  
    this.playersGrid.UnselectAll();  
 
    foreach (var item in ((IList)this.playersGrid.ItemsSource))  
    {  
        if (!oldSelectedItems.Contains(item))  
            this.playersGrid.SelectedItems.Add(item);  
    }  
}  
 
private void ReverseWithSelectAll()  
{  
    var oldSelectedItems = this.playersGrid.SelectedItems.ToList();  
    this.playersGrid.SelectAll();  
 
    foreach (var item in oldSelectedItems)  
    {  
        this.playersGrid.SelectedItems.Remove(item);  
    }  

The ReverseSelection method will reverse the selection using the fast UnselectAll and SelectAll methods.

RadGridView has a property called IsBusy that controls the visibility of its loading indicator - when set to true the loading indicator is show. You can use this property to control the loading indicator when you are wating for a response from a service call.

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.
0
Hector
Top achievements
Rank 1
answered on 27 Aug 2009, 05:28 PM
Hi Milan.  I have a similiar situation where I have a checkbox that selects/unselects all from a checkbox.  It was working beautifully in previous versions of TelerikRadControls, but now the UnselectAll() function is not working.  Do you have an idea what I might be doing wrong?  Here is my code, which is executed from the checkbox check/unchec events:

private void chkSel_Unsel_Checked(object sender, RoutedEventArgs e)  
        {  
            _SelectedValidValues.Clear();  
            this.gridMultiSelect.IsBusy = true;  
            if (chkSel_Unsel.IsChecked == true)  
            {  
                gridMultiSelect.SelectAll();  
                foreach (ValidValues val in gridMultiSelect.SelectedItems)  
                {  
                    _SelectedValidValues.Add(val);  
                }  
            }  
            else  
            {  
                this.gridMultiSelect.UnselectAll();  
            }  
            this.gridMultiSelect.IsBusy = false;  
        } 
0
Hector
Top achievements
Rank 1
answered on 27 Aug 2009, 06:20 PM
I found this:

this

 

.gridMultiSelect.SelectedItems.Clear();
works as an alternative.

 

 

 

 

 

0
Milan
Telerik team
answered on 28 Aug 2009, 05:08 AM
Hi Hector,

Just to be sure - could you share which version of the RadControls for Silverlight are you using? The ticket information reports 2009.1.526? Weren't you using a more recent version?

Best wishes,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Hector
Top achievements
Rank 1
answered on 28 Aug 2009, 12:55 PM
Milan, I am using 2009.2.812.1030
0
Milan
Telerik team
answered on 31 Aug 2009, 11:57 AM
Hi Hector,


Sincerely yours,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Hector
Top achievements
Rank 1
answered on 31 Aug 2009, 12:56 PM
Hi, Milan.
0
Milan
Telerik team
answered on 03 Sep 2009, 06:59 PM
Hi Hector,

Sorry for the the delay but we have been working on some performance improvements of our selection mechanism so the selection should work faster.

I am sending you a sample application that has the latest improvements. We can actually make it even faster but that requires a custom build that eliminates the legacy property SelectedRecords.

Unfortunately I was not able to reproduce the problem that you have described in your previous post. Could send a sample that could help me to reproduce the problem?

Sincerely yours,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Hector
Top achievements
Rank 1
answered on 02 Oct 2009, 06:15 PM
Hi Milan.  I just discovered that the UnselectAll() function is not working when I have my gridview with groups.  If I don't add groups it works.  Can you verify this?
0
Milan
Telerik team
answered on 06 Oct 2009, 06:51 AM
Hello Hector,

This issue has been fixed in our latest internal build for Q2 2009 SP1. If upgrading is not possible you can just use this.RadGridView1.SelectedRecords.Clear();

Best wishes,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Hector
Top achievements
Rank 1
answered on 06 Oct 2009, 07:47 PM
Thanks Milan.  I have another question.  I have a collection list of items I want to add to the selection.  I can easily do it by iterating over each one and add them to the SelectedItems collection individually.  However, this take hit on performance especially if the list is long.  Is there a way of setting my entire list ot the selected list?  Here is what I have so far:
// Selected values is private List<Object> _SelectedValidValues = new List<Object>();  
            for (int x = 0; x < _SelectedValidValues.Count; x++)  
            {  
                gridMultiSelect.SelectedItems.Add(_SelectedValidValues[x]);  
            }  
              
 
//This is what I want but will not work:  
gridMultiSelect.SelectedItems.ToList().AddRange(_SelectedValidValues); 

If you can see on my code, I have already tried gridMultiSelect.SelectedItems.ToList().AddRange(_SelectedValidValues); but will not add anything to the selected set.

Thanks,
Hector
0
Milan
Telerik team
answered on 07 Oct 2009, 12:05 PM
Hello Hector,

How many items are you dealing with?

You could try to select the items asynchronously by using the Dispatcher and a BackgroundWorker. I have prepared a sample applicatation that demonstrates the async approach.

You can also try our latest internal build for Q2 2009 which includes several performance improvements in our selection machanism.

All the best,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Hector
Top achievements
Rank 1
answered on 07 Oct 2009, 03:18 PM
Thanks Milan for the quick response.  I took a quick look at your project and upgraded with the internal build... there is still a delay.  I will try out the asyncronous selection later, right now I have other fish to fry.  My problem is actually not the selection part.  It selects pretty fast, however, my problem is due to the intrinsict Gridview behavior to unselect everything selected when a row is clicked on.  What I need is to be able to select multiple rows without having to press the Control key.  I want the exact behavior as if you had the control key pressed, but not have it pressed. 
I was able to achieve this with your help by keeping track of the selection by adding or removing to a list every time a row is clicked.  When ever the selection changes, I just add everything from the list to the gridview.selecteditems.  The only thing is that this is a slow process.  I will upload a sample project to show you better what I am talking about.  Thanks for everything.

-Hector
0
Milan
Telerik team
answered on 07 Oct 2009, 03:37 PM
Hello Hector,

Well, I have a very good news! We have recently implemented what Microsoft calls Multiple Selection - the ability to select multiple rows by using the mouse only. Since you have downloaded our latest build you should see the property SelectionMode on RadGridView. Just set it to Multiple and you should get the desired behaviour out of the box.

Kind regards,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Hector
Top achievements
Rank 1
answered on 07 Oct 2009, 04:04 PM
That is music to my ears!  I just tried it and it works excellent.  Thanks Milan, Telerik Rocks!
0
Hector
Top achievements
Rank 1
answered on 07 Oct 2009, 04:24 PM
One more question...how do I upgrade the DLLs withouth getting the "Telerik Trial Version" water mark to appear when pushing it to a web server?  We have paid for a production license.  Also, how can I tell what DLLs are trial and which are not?  Thanks
0
Hristo
Telerik team
answered on 08 Oct 2009, 11:26 AM
Hi Hector,

In order to stop viewing the trial message you need to download the developer version of our Silverlight controls and replace the trial DLLs with the development ones. You can do that from Your Account->Downloads->RadControls for Silverlight. The trial versions have Trial in their names and the developer versions have Dev. Once you have purchased a license for some of our suites you can download only the Dev versions.

Please let me know if I can be of further assistance.

Sincerely yours,
Hristo
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Hector
Top achievements
Rank 1
answered on 08 Oct 2009, 01:22 PM
Oh, I see, it says Trial Version is in the description of the dll, not the file name.  I asked because I thought I had replaced all the trial dlls with the production ones, but the trial message still appeared.  I guess I must not have replace them all because I tried again and now the trial message is no more.  Thanks.
Asked by
simeon
Top achievements
Rank 1
Answers by
Milan
Telerik team
Hector
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or