Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataGrid requests when shift multiselection with data virtualization

Adding up on a post of 4 months ago which unfortunately didn't receive any answer.

I'm basically standing before the same problem when using multiselection in a datagrid with shift.

When in somewhere in the middle of a huge list (say it's 1,000,000 items in the grid, all data virtualized) and I were to select from 500,000 to 500,050 using shift + mouse click, the grid calls the "GetEnumerator()" method of my virtual list (similar implementation to Vincent's and Paul's). What I did until now was just a SelectMany on the cached pages. But unfortunately resulted in the rows not being properly selected (while ctrl + mouse click does the job!).

So what I found is, that the DataGrid actually expects all items from index 0 to the last of the selection. This, obviously, isn't ideal for a list of 1m items as this would result in requests for each and every item from 0 till (in my example) 500,050 and thus loading everything form database.

So my questions would be the same as those of Daniel in th elinked posted above:

  • Why does the DataGrid request items multiple times (selected items are requested ~6-7 times in a row for no apparent reason)?

  • Is there a way to tell the DataGrid not to use the Enumerator and to just take the items selected and not iterate through from 0 on?

Thank you very much, hoping I have more luck in getting at least thought provoking answers, as there isn't much to be found concerning data virtualization.

like image 941
Alex Endris Avatar asked Jan 15 '13 14:01

Alex Endris


1 Answers

I found a solution to this problem (at least I can say it works for me).

What I basically did was fooling the VirtualList as such that I do the following code:

for (int i = 0; i < Count; i++)
{
  int pageIndex = i/PageSize;
  int pageOffset = i%PageSize;
  IList<TItem> page;
  if (pages.TryGetValue(pageIndex, out page))
  {
    yield return page[pageOffset];
  }
  yield return default(TItem);
}

That way I will always get the items that are really in the list, but return nothing when it is part of the virtualization.

Of course this can result in some other problems, but this is so far the closest I got concerning this.

like image 119
Alex Endris Avatar answered Oct 14 '22 05:10

Alex Endris