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
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).
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
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
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
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
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
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
}
}
}
}
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
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
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
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
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
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