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

Check for Single Selection when SelectionMode=Extended

3 Answers 102 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Christian
Top achievements
Rank 1
Christian asked on 22 Jun 2015, 08:46 AM

Hi,

I have a RadGridView with SelectionMode=Extended.

When I select only one row I want to perform a certain action. However there does not seem to be an easy way to detect if one or more items are selected when I select the items by dragging selection.

The SelectionChanged event is already fired on MouseDown and then for every new item. It would be great if the event could be delayed until the mousebutton is up again.

I tried to use MouseDown and MouseUp events to check the Mouse button state, but RadGridView first fires the SelectionChanged event and afterwards the MouseUp event, so that did not work,.

 

Do you have any suggestions how to do this?

 

Best regards

3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 24 Jun 2015, 03:02 PM
Hi,

Have you tried subscribing for the FrameworkElement.MouseLeftButtonDownEvent on level RadGridView (this.grid):
this.grid.AddHandler(FrameworkElement.MouseLeftButtonDownEvent,new MouseButtonEventHandler(OnMouseLeftButtonDown), true);
...
  
private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    var row = (e.OriginalSource as FrameworkElement).ParentOfType<GridViewRow>();
    if (row != null)
    {
        // code related to clicked cell here
    }
}

Regards,
Dimitrina
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Christian
Top achievements
Rank 1
answered on 29 Jun 2015, 08:39 AM

Hello,

thanks for your answer.

Can you show me how this helps to find out if there is single or dragging selection?

 

Best regards

0
Dimitrina
Telerik team
answered on 01 Jul 2015, 04:15 PM
Hello,

As it turns out subscribing for the MouseLeftButtonUpEvent (this was the intended event, not MouseLeftButtonDownEvent) can only detect how many items are selected at all in RadGridView. 
For example:
private void OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
    var currentlySelectedItems = clubsGrid.SelectedItems;
}

There is not a way to distinguish between rows selected with this interaction or selected previously.

You are right that the SelectionChanging and SelectionChanged events are raised per one item only, not for all. I am afraid there is not such an API to hold an information how many items are selected while extended select.

Regards,
Dimitrina
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
GridView
Asked by
Christian
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Christian
Top achievements
Rank 1
Share this question
or