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

RadGridView VirtualQueryableCollectionView Selected items (Shift + click)

8 Answers 129 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Rakesh
Top achievements
Rank 1
Rakesh asked on 10 Oct 2013, 07:26 PM
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.

8 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 11 Oct 2013, 07:07 AM
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 >>
0
Rakesh
Top achievements
Rank 1
answered on 11 Oct 2013, 04:00 PM
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.
0
Rakesh
Top achievements
Rank 1
answered on 15 Oct 2013, 09:19 PM
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.
0
Maya
Telerik team
answered on 16 Oct 2013, 11:45 AM
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 >>
0
Rakesh
Top achievements
Rank 1
answered on 18 Oct 2013, 03:55 PM
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

0
Maya
Telerik team
answered on 21 Oct 2013, 11:42 AM
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 >>
0
Rakesh
Top achievements
Rank 1
answered on 22 Oct 2013, 08:31 PM
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
0
Maya
Telerik team
answered on 25 Oct 2013, 07:46 AM
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 >>
Tags
GridView
Asked by
Rakesh
Top achievements
Rank 1
Answers by
Maya
Telerik team
Rakesh
Top achievements
Rank 1
Share this question
or