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

All selected rows loading before SelectionChanging completed

16 Answers 213 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Valerie
Top achievements
Rank 1
Valerie asked on 03 Feb 2014, 03:40 PM
We use VirtualQueryableCollectionView because our data sets are very large. For the same reason, we need to restrict the number of items the user can select. We do this by hooking into the SelectionChanging event and if the number selected exceeds our limit we put up a message telling them they need to select fewer rows. We then cancel the select.

Presumably the way the user selected so many rows was to select a row and then scroll quickly to a page much further down and shift-click another row. The problem is that when we show the message to say they exceeded the limit, the RadGridView is making the calls to load all the rows that would be part of that selection. This defeats the point of having the limit. Those rows should only be loaded on a SelectionChanged, not a SelectionChanging, since the latter can be cancelled. Our entire application locks up and eventually gets an out-of-memory from trying to load all the rows that shouldn't be loading.

Is there a way to stop the grid from loading those rows before the SelectionChanged event has occurred. 

Thank you.

16 Answers, 1 is accepted

Sort by
0
Valerie
Top achievements
Rank 1
answered on 04 Feb 2014, 12:49 AM
I put logging in and I see that all the requests to get the rows are made before SelectionChanging is called, so there is no opportunity for me to intercept it and say, set a flag to say to ignore the requests to load the rows while the in the SelectionChanging callback method. By the time the callback is made all the requests to load the rows (there can be hundreds of thousands) have been made. How can I stop this loading?
0
Dimitrina
Telerik team
answered on 06 Feb 2014, 02:55 PM
Hi,

Extended selection with VirtualQueryableCollectionView is only recommended when the selected items are in the View area. It is not possible to actually select items outside it as the items to be eventually displayed are still not presented. This is the case until the user scrolls to a particular position so that the items to be displayed into view are actually loaded. Once the load is requested (as the user releases the mouse), you cannot stop this.
I am afraid this collection was designed to serve mostly ReadOnly scenarios and its capabilities are limited.

I would suggest you to use QueryableCollectionView and DataPager instead. You can check our WPF Demos on our RadDataPager.

Regards,
Didie
Telerik

Check out the new Telerik Platform - the only modular platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native apps. Register for the free online keynote and webinar to learn more about the Platform on Wednesday, February 12, 2014 at 11:00 a.m. ET (8:00 a.m. PT).

0
Valerie
Top achievements
Rank 1
answered on 18 Feb 2014, 02:41 PM
Hello,
I can't switch to using a QueryableCollectionView and DataPager as this product has been in development for more than a year and is built around the VirtualQueryableCollectionView.

I am looking for a workaround and I found one event that I can hook into before the loading of the items takes place, namely RadGridView.PreviewMouseDownEvent. My question now is if there is a way from the sender object on this event I can find out which row the mouse-down occurred on. The sender object is a RadGridView. Or maybe using information from that object along with the mouse coordinates? What I am trying to accomplish is doing my own calculation of how many rows were selected.
Thank you




0
Valerie
Top achievements
Rank 1
answered on 18 Feb 2014, 05:28 PM
oh, and even if I need to use reflection to get to some of those internal properties/fields. That's ok too.
0
Valerie
Top achievements
Rank 1
answered on 19 Feb 2014, 05:37 AM
I figured out a solution but it has one problem. The solution is to hook PreviewMouseDown and in the handler test myself if the number of records exceeds my limit by comparing the distance between the SelectedItem and the clickedRow's item in the Items.SourceCollection of the VirtualQueryableCollectionView. If it exceeds the limit, then set a flag so that the VirtualQueryableCollectionView's ItemsLoading callback method returns null instead of returning the requested rows.

I then reset the flag inside the SelectionChanging hooke method .

The problem is that once I do this, Telerik no longer calls the ItemsLoading method for those rows. Even though null was returned for them, and they appear as null in Items.SourceCollection, they appear as empty rows in the grid UI and never call back to get the data again. Is there a way i can tell the VirtualQCV to refresh those rows, not to use the null values that were returned to them? Even if I need to use reflection to access anything private. Thank you

0
Dimitrina
Telerik team
answered on 20 Feb 2014, 02:49 PM
Hi,

You could also subscribe for the PreviewMouseDown event on a GridViewCell level.
For example:

this.clubsGrid.AddHandler(GridViewCell.PreviewMouseDownEvent, new MouseButtonEventHandler(Cell_Click), true);
private void Cell_Click(object sender, MouseButtonEventArgs e)
{
    var clickedRow = (e.OriginalSource as TextBlock).ParentOfType<GridViewRow>();
}

As to your second question, you could try invoking ResetItems(startIndex, count) method of VQCV.

Regards,
Didie
Telerik
0
Valerie
Top achievements
Rank 1
answered on 20 Feb 2014, 02:58 PM
Hi Didie,
I did discover the ResetItems(startIndex, count) and tried to use it. However, those rows never got reset because when I scrolled to them they never called back the ItemsLoading method. As a test I also called ResetItems on some rows that had been loaded before the shift-click and those DID call back the ItemsLoading method. I also tried letting the stack unwind and then via a timer I called ResetItems on those rows but that too did not work. That doesn't make sense to me. Is there something special about rows that are loaded because of a shift-click that they won't reset?
Thank you, Valerie
0
Dimitrina
Telerik team
answered on 21 Feb 2014, 11:28 AM
Hi,

You could also try resetting the VirtualItemCount. When the VirtualItemCount of the virtual collection is changed the collection will raise Reset CollectionChanged.  Does this work for you?
 
You can also check our online documentation.

Regards,
Didie
Telerik
0
Valerie
Top achievements
Rank 1
answered on 26 Feb 2014, 05:14 PM
Thank you Didie,
Resetting the VirtualItemCount is now forcing a refresh so my rows are loaded. Yay. I would have liked to just get a refresh of the rows that had null returned but at least this works.

I then tried to reselect the rows that had been selected before the user did the shift-click. I can do that for a single row via ScrollIndexIntoViewAsync followed by setting CurrentItem. But if I try to select rows by adding the objects to Grid.SelectedItems those items don't highlight. I will enter a new forum post for this as I don't want to muddy the picture under this post. So thank you.

Here is the code I used to halt the loading of the rows while determining if they exceed our limit. And then the reset afterwards.
private void GridEventHandler_OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    // This is the one event that gets fired when the user clicks on a row BEFORE any more rows get hydrated from the database.
    // So test if the user is trying to select more rows by holding down the shift key. If so, and if that number exceeds the number we
    // allow to be selected at once, prevent those rows from being loaded by setting IsHaltLoadingDocs. Note that the rows may already be
    // loaded. That's ok. We just want to prevent Telerik from trying to get all those rows if it doesn't have them already as it could
    // overwhelm memory.
    // Note that after we set IsHaltLoadingDocs=true, it gets reset to false in GridEventHandler_SelectionChanging after the latter has told
    // the user it can't do the selection and cancels it.
    var gridViewDataControl = sender as RadGridView;
    var clickedRow = (e.OriginalSource as UIElement) != null ? (e.OriginalSource as UIElement).ParentOfType<GridViewRow>() : null;
    var docListVM = Grid.DataContext as DocumentListViewModel; // this is the class with the callback method for ItemsLoading on the grid
 
    if (gridViewDataControl != null && clickedRow != null && docListVM != null)
    {
        new Logger().LogTrace("GridEventHandler_OnPreviewMouseLeftButtonDown");
        if (Keyboard.Modifiers == ModifierKeys.Shift)
        {
            var selItem = gridViewDataControl.SelectedItem; // previously selected item
            var clickedItem = clickedRow.Item; // currently selected item
 
            var srcColl = gridViewDataControl.Items.SourceCollection;
            var srcList = srcColl.Cast<object>().ToList(); // convert IEnumerable to List so we can walk it multiple times
 
            // find the position of the item in the Telerik array that is part of the VirtualQueryableCollectionView. The size of the array is the number of
            // virtual rows, and unloaded rows are set to null.
            int clickedIndex = srcList.FindIndex(s => s != null && s.Equals(clickedItem));
            int selIndex = srcList.FindIndex(s => s != null && s.Equals(selItem));
 
            if (clickedIndex != -1 && selIndex != -1 && (Math.Abs(clickedIndex - selIndex + 1) > ((IMultiSelectable)Grid.DataContext).MaxCanSelect))
            {
                //this.LogTrace("GridEventHandler_OnPreviewMouseLeftButtonDown: setting halt to true");
                docListVM.IsHaltLoadingDocs = true; // the ItemsLoading method will ignore Telerik's requests to load rows
                _numSelectedRows = Math.Abs(clickedIndex - selIndex + 1); // track the actual number of selected rows
            }
            else
            {
                _numSelectedRows = -1;
            }
        }
    }
}
 
 
 
private void GridEventHandler_SelectionChanging(object sender, Telerik.Windows.Controls.SelectionChangingEventArgs e)
{
    var docVM = Grid.DataContext as DocumentListViewModel;
    if (docVM != null)
    {
        try
        {
            var clickedRow = (e.OriginalSource as UIElement) != null ? (e.OriginalSource as UIElement).ParentOfType<GridViewRow>() : null;
            ISelectAllMode handler = _actionHandler as ISelectAllMode;
            if (handler != null)
            {
                if (
                    // this method decides if they've exceeded the rows and puts up a dialog and returns true
                    handler.DisallowItemSelection(_numSelectedRows == -1
                                                    ? this.Grid.SelectedItems.Count + e.AddedItems.Count - e.RemovedItems.Count
                                                    : _numSelectedRows) == true)
                {
                    e.Cancel = true;
                }
            }
        }
        finally
        {
            //this.LogTrace("GridEventHandler_SelectionChanging: setting halt to false");
            _numSelectedRows = -1;
            if (docVM.IsHaltLoadingDocs == true)
            {
                docVM.IsHaltLoadingDocs = false; // this call has the side-effect of resetting the virtual count that causes the rows to reload
            }
        }
    }
}





0
Dimitrina
Telerik team
answered on 28 Feb 2014, 12:46 PM
Hello,

I am afraid I cannot suggest you a better way to reset the items than the already suggested ones.

As to the problem with additionally selecting rows, a possible reason why your approach does not work would be that you have different instances of the items than populated to the GridView.
I am going to further investigate the issue in the demo solution you sent in the support ticket you opened on the same topic. 

Regards,
Didie
Telerik
0
dev
Top achievements
Rank 1
answered on 18 Apr 2017, 09:27 AM
In my case when i do the selection using first click on single item and scroll down to 4000+ documents and again click using shift+click the UI goes on hanging state for at least 45 seconds each time. Hope i can get valuable reply as earlier as possible. I am very much sure about "GridEventHandler_SelectionChanged" when clicked on Shift+Click, it's skipped out to this methods and after that which function it is calling seems unknown to me. I need some satisfy solution for this this scenarios.
0
Stefan Nenchev
Telerik team
answered on 21 Apr 2017, 06:35 AM
Hello ,

I have tested the behavior in a standard scenario and it does not take such long period to select such amount of items. Please share more information regarding the setup on your end.

Regards,
Stefan Nenchev
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which you to write beautiful native mobile apps using a single shared C# codebase.
0
dev
Top achievements
Rank 1
answered on 21 Apr 2017, 07:37 AM

Let me try to explain step by steps

1. Selection of first document by single click on one document(see attachment CaptureFirst45.jpeg) Result--> No Issue

2. Scroll down to the 4000+ documents and click(selection happening) using Shift+Click(very specific) button(see attachments CaptureSecond45.jepg) Result--> Almost hangs for minimum 45 seconds .

3. In 3rd steps if i'll do the single selection on the file between first Selection and 2nd selection it will get hanged again for minimum 45 seconds.(See attachments SingleClick45.jpeg)

The Setup environment for my Telerik UI

1. I'm using Windows 10 64bit version having 8GB RAM and 320GB HDD and Intel i5 Processor. Sorry i am not sure about the version of my Telerik version but my QA has checked for all the OS and Version. It still not solved for us. 

Hope this information will help to get better understanding about the issues.

 

thanks

Dev

0
Stefan Nenchev
Telerik team
answered on 25 Apr 2017, 10:05 AM
Hello,

Please track the support ticket which you have raised where we can discuss your specific scenario and try to find what is causing the issue.

Regards,
Stefan Nenchev
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which you to write beautiful native mobile apps using a single shared C# codebase.
0
dev
Top achievements
Rank 1
answered on 16 May 2017, 06:27 AM

Hi All,

           I am looking for the difference between  UI for WPF R2 2017 and  Telerik Reporting R2 2017 (version 11.1.17.503). In the Telerik websites it seems the same released date date i.e 3 May 2017 but they have mentioned different fixes and new features in both the links. I am sharing a links for better and quick reply.

http://www.telerik.com/support/whats-new/wpf/release-history/ui-for-wpf-r2-2017

http://www.telerik.com/support/whats-new/reporting/release-history/telerik-reporting-r2-2017-(version-11-1-17-503)

Regards

Dev

0
Martin Ivanov
Telerik team
answered on 18 May 2017, 01:58 PM
Hello Dev,

UI for WPF and Telerik Reporting are completely different products. The UI for WPF suite is a rich set of UI components build for the Windows Presentation Foundation framework. On the other hand Telerik Reporting is a set of tools and services for creating, deploying and using reports for variety of .NET platforms.

Note that the Telerik Reporting product allows you to use it also in a WPF application which uses few of the controls from the UI for WPF suite. You can read more about this in the reporting documentation.

Regards,
Martin Ivanov
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
Valerie
Top achievements
Rank 1
Answers by
Valerie
Top achievements
Rank 1
Dimitrina
Telerik team
dev
Top achievements
Rank 1
Stefan Nenchev
Telerik team
Martin Ivanov
Telerik team
Share this question
or