Check for Single Selection when SelectionMode=Extended

4 posts, 0 answers
  1. Christian
    Christian avatar
    52 posts
    Member since:
    Apr 2011

    Posted 22 Jun 2015 Link to this post

    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

  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 24 Jun 2015 Link to this post

    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
  3. DevCraft banner
  4. Christian
    Christian avatar
    52 posts
    Member since:
    Apr 2011

    Posted 29 Jun 2015 in reply to Dimitrina Link to this post

    Hello,

    thanks for your answer.

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

     

    Best regards

  5. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 01 Jul 2015 Link to this post

    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
Back to Top