RadGridView VirtualQueryableCollectionView Selected items (Shift + click)

9 posts, 0 answers
  1. Rakesh
    Rakesh avatar
    23 posts
    Member since:
    May 2013

    Posted 10 Oct 2013 Link to this post

    Hi
    I have a radgrid with virtual collection which loads 500 (virtual count) at a time. When I initially load the grid it has 500 rows loaded and the totalcount is 20000. I am selecting first row and dragging the scrollbar to the bottom and using shift+click on the last row. At this time I want all the 20000 rows to be selected but its not happening. I see only around 520 rows(the first 500 and last 20) are selected. How can I achieve selecting all the rows in between the first selected row and the shift+click row. Any help is much appreciated.
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 11 Oct 2013 Link to this post

    Hello Rakesh,

    Please check out this forum thread for a reference. 

    Regards,
    Maya
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Rakesh
    Rakesh avatar
    23 posts
    Member since:
    May 2013

    Posted 11 Oct 2013 Link to this post

    Hi
    Thanks for the quick reply. I have gone through that thread and it looks like it is not achieveble to get all the rows between first selected row and shift +click row when using virtualqueryablecollectionview. Is that true or did I miss anything?? If so do you have any other approaches to achieve this.
  5. Rakesh
    Rakesh avatar
    23 posts
    Member since:
    May 2013

    Posted 15 Oct 2013 Link to this post

    Hi
    Can anyone help with the above issue. How do I find out if the user has shift+clicked on the grid. Also How would I find out the first selected row and the shift+clicked row. I want to load all the rows between these two. Any help is much appreciated.
  6. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 16 Oct 2013 Link to this post

    Hi Rakesh,

    You need to load all items that you want to select. I am attaching a sample project illustrating a possible way to go. It might need some improvements depending on your exact scenario, but the idea should be to load all the items to be selected (or if appropriate - all items).

    Regards,
    Maya
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  7. Rakesh
    Rakesh avatar
    23 posts
    Member since:
    May 2013

    Posted 18 Oct 2013 Link to this post

    Hi Maya
    Thanks for the solution. I am still facing issues. As you suggested I had MouseleftbuttonDown event where I have the firstindex and last index. But this event is getting fired after SelectionChanged event where selection is already done.Anyways. In MouseleftbuttonDown event I am fetching all the rows I need but how do I select them again since selection is already done,I need to change the selected items. Moreover MouseleftbuttonDown  event is fired about 5 or 6 times on every click. Why is it so??

    Thanks
    Rakesh

  8. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 21 Oct 2013 Link to this post

    Hi Rakesh,

    Generally, once you have the items loaded, you can add them to the SelectedItems collection. As for firing MouseLeftButtonDown event - will it be possible to clarify a bit ? When is it fired ? Is it for different sources ? What are the steps you follow for reproducing it ?

    Regards,
    Maya
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  9. Rakesh
    Rakesh avatar
    23 posts
    Member since:
    May 2013

    Posted 22 Oct 2013 Link to this post

    Hi Maya
    I have three events for my grid 
    GridEventHandler_SelectionChanging(object sender, Telerik.Windows.Controls.SelectionChangingEventArgs e),
    GridEventHandler_SelectionChanged(object sender, SelectionChangeEventArgs e), 
    GridEventHandler_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    The events are fired as ordered above so by the time MouseButtonDown is fired my selection is already done and all the items which are not loaded are not selected. So in the MouseButtonDown event I am doing the following

     private static void GridEventHandler_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
            {
                try
                {
                    var gridViewDataControl = sender as RadGridView;
                    var clickedRow = (e.OriginalSource as UIElement) != null ? (e.OriginalSource as UIElement).ParentOfType<GridViewRow>() : null;
                    if (gridViewDataControl!=null && clickedRow != null)
                    {
                        if (Keyboard.Modifiers == ModifierKeys.Shift)
                        {
                            var startindex = gridViewDataControl.Items.IndexOf(gridViewDataControl.SelectedItems[0]);
                            int lastIndex = gridViewDataControl.Items.IndexOf(clickedRow.Item);
                            //If the user selects from bottom and shift selects on top then load from top to bottom so interchanging indexes.
                            if(startindex > lastIndex)
                            {
                                int tempstartindex = startindex;
                                startindex = lastIndex;
                                lastIndex = tempstartindex;
                            
                            }
                            if(startindex!=lastIndex && gridViewDataControl.SelectedItems.Count!= (lastIndex - startindex)+1)
                            {                           
                             var docListVM = gridViewDataControl.DataContext as DocumentListViewModel;
    VirtualQueryableCollectionView virtualCollection = docListVM.ListItems;
    IEnumerable<Document> docs = docListVM.GetDocumentsInRange(startindex, lastIndex - startindex + 1);
    virtualCollection.Load(startindex, docs);
    SetSelectionHighlighting(gridViewDataControl, startindex, lastIndex);
                            }
                        }
                    }              
                }
                catch (Exception ex)
                {
                    new Logger().LogDebug("RadGridViewActionBehavior.GridEventHandler_OnMouseLeftButtonDown caught exception: " + ex.Message);
                }            
            }


    private static void SetSelectionHighlighting(RadGridView radGridView, int firstSelectedItem, int lastSelectedItem)
    {
    int i = 0;
    IEnumerable<GridViewRow> rows = radGridView.ChildrenOfType<GridViewRow>();
    foreach (var gridViewRow in rows)
    {
    if (!(gridViewRow is GridViewNewRow) && !(gridViewRow is GridViewHeaderRow))
    {
    i++;
    if ((i >= firstSelectedItem) && (i <= lastSelectedItem))
    {
    gridViewRow.IsSelected = true;
    }
    }
    }
    }

    In my method I am selecting each row which is skipped from selection. But I see the items are not selected in the grid.  Can you please help me with this how to make my rows get selected.

    Thanks
    Rakesh
  10. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 25 Oct 2013 Link to this post

    Hello Rakesh,

    Will it be possible to try adding the items to the SelectedItems collection of the grid rather than setting IsSelected property of the row ? Do you get the same result ? 

    Regards,
    Maya
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top
UI for WPF is Visual Studio 2017 Ready