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
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.
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; |
} |
this
.gridMultiSelect.SelectedItems.Clear();
works as an alternative.
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.
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.
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.
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.
// 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
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.
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
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.
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.