Hello.
I'm using NetAdvantage WebClient Trial 2009.2 to evaluation.
I want to implement "Ctrl-A" like function.
So I need to select all rows in xamWebGrid.
I try this code first:
foreach (var x in webgrid.Rows){ webgrid.SelectionSettings.SelectedRows.Add(x);}
but this is too slow.
So I tryed an other code:
webgrid.SelectionSettings.SelectedRows.AddRange(webgrid.Rows);
but it does'nt match Type of Arg.
Rows is RowCollection, not match SelectedCollectionBase<Row>.
Please tell me good performance way to do it.
Hi,
Could you provide more details about what exactly is the behavior that you consider slow?
Thanks,
Thanks for reply.1. I create a instance of XamWebGrid and set a event handler to KeyDown event.2. set Data (it has 10,000 rows) to XamWebGrid.ItemsSource.3. select all rows by XamWebGrid.SelectionSettings.SelectedRows.AddProcess takes about 20 sec at step 3.But, User can select all rows by mouse, "Click first row and Shift-Click last row".It takes about 0 sec.So, I say "too slow".I think SelectedRows.Add is too slow.Code is this:using System.Collections.Generic;using System.Windows;using System.Windows.Controls;using Infragistics.Silverlight.Controls;using Infragistics.Silverlight;namespace sample{ public partial class MainPage : UserControl { private XamWebGrid webGrid; public MainPage() { InitializeComponent(); } private void ButtonSearch_Click(object sender, RoutedEventArgs e) { webGrid = new XamWebGrid(); webGrid.EditingSettings.AllowEditing = EditingType.None; webGrid.SelectionSettings.CellClickAction = CellSelectionAction.SelectRow; webGrid.SelectionSettings.RowSelection = SelectionType.Multiple; webGrid.KeyDown += new System.Windows.Input.KeyEventHandler(onKeyDown); Grid.SetColumn(webGrid, 1); LayoutRoot.Children.Add(webGrid); List<sampleWebService.ITEM> testdata = new List<sampleWebService.ITEM>(); for (int i = 0; i < 10000; ++i) { sampleWebService.ITEM item = new sampleWebService.ITEM(); item.ATTR1 = i.ToString(); testdata.Add(item); } webGrid.ItemsSource = testdata; } private void onKeyDown(object sender, System.Windows.Input.KeyEventArgs e) { // Ctrl-A if (e.Key == System.Windows.Input.Key.A && System.Windows.Input.Keyboard.Modifiers == System.Windows.Input.ModifierKeys.Control) { foreach (var x in webGrid.Rows) { webGrid.SelectionSettings.SelectedRows.Add(x); } } } }}
I've been able to reproduce your issue but unfortunately currently there isn't other way to make the selection programatically without this delay.
Regards,
Thanks Stoimen.
I hope fix type of "addrange" in next version NetAdvantage for Silverlight.
and I can write:
webGrid.SelectionSettings.SelectedRows.AddRange(webGrid.rows);
or, Add "ctrl-A" action such as DataGrid has.
Thanks.
I agree, that we need to make this simpler in the future, it was just a use case that we overlooked.
However, it is currently possible, with just a little bit of extra work, for now.
First, create a new class that derives from SelectedRowsCollection. We're going to do this, to expose a protected method, that will make it possible to make Selection quicker:
public class CustomSelection : SelectedRowsCollection
{
public void AddSelectItem(Row r)
this.SelectItem(r, true);
}
Now, in a button click, you can do the following:
private void Button_Click(object sender, RoutedEventArgs e)
CustomSelection src = new CustomSelection();
foreach (Row r in this.DataGrid1.Rows)
src.AddSelectItem(r);
this.DataGrid1.SelectionSettings.SelectedRows.AddRange(src);
Note, we do plan on making this easier to achieve in the future, but for now, i hope this helps.
-SteveZ
Hi, Stephan.
Thank you more information.
I tried your code, and it works.
Time reduced from 20 sec to 8 sec in 10,000 rows data.
It is better solution!
I add a little information.
In First time, this code takes 8 sec:
var src = new CustomSelection();foreach (Row r in this.XamWebGrid.Rows){ src.AddSelectItem(r);}
But in second time, it takes 0.03 sec.
I don't know Why it is.