UnSelect in single mode

6 posts, 1 answers
  1. David Brenchley
    David  Brenchley avatar
    67 posts
    Member since:
    Jun 2010

    Posted 20 Oct 2011 Link to this post

    How do I get the GridView to unselect a row when selection mode is Single?  If not, is there a way to only allow a single row to be selected when selection mode is extended or multiple?
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 21 Oct 2011 Link to this post

    Hi David Brenchley,

    There are a couple of ways to go:
    1. You can call UnselectAll() method of RadGridView.
    2. You can clear the SelectedItem property;
    3. You can clear the SelectedItems collection.
    When do you want to clear the selection ? What is the exact scenario that you want to achieve ?
     

    Best wishes,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. UI for WPF is Visual Studio 2017 Ready
  4. David Brenchley
    David  Brenchley avatar
    67 posts
    Member since:
    Jun 2010

    Posted 24 Oct 2011 Link to this post

    What I would like to be able to do is to have the option to have nothing selected in the grid or to only have 1 row selected.  If the user doesn't want a row selected and had accidentally selected one, it would be nice to have the ability to unselect that row.
  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 25 Oct 2011 Link to this post

    Hi David Brenchley,

    Would you clarify a bit how do you expect this item to be deselected - do you want to click on it, to click on another item and clear all selected items, click outside the grid ? What is the exact scenario that you want to achieve ? 
     

    All the best,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  6. David Brenchley
    David  Brenchley avatar
    67 posts
    Member since:
    Jun 2010

    Posted 25 Oct 2011 Link to this post

    Here is what I want to happen.
    1.  I only want one row to be selected at a time.  Any other rows to be deselected when a row is selected.
    2.  I want to be able to un-select that row by clicking on the row so that no rows at all are selected.
  7. Answer
    Maya
    Admin
    Maya avatar
    4062 posts

    Posted 27 Oct 2011 Link to this post

    Hi David,

    You can try to set CanUserSelect property of RadGridView to "False" and handle PreviewMouseKeyDown event like follows:

    public MainWindow()
            {
                InitializeComponent();
                this.clubsGrid.IsReadOnly = true;
                this.AddHandler(RadGridView.PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(OnPreviewMouseDown), true);
            }
     
            private void OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
            {
                FrameworkElement clickedElement = e.OriginalSource as FrameworkElement;
                GridViewRow clickedRow = clickedElement.ParentOfType<GridViewRow>();
                if (clickedRow != null)
                {
                    clickedRow.IsSelected = !clickedRow.IsSelected;
                }
            }

    On the other hand, each item can be unselected by clicking on it while holding Cntr key. 
    Let me know whether the suggested approach meets your requirements.

    All the best,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top
UI for WPF is Visual Studio 2017 Ready