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

UnSelect in single mode

5 Answers 320 Views
GridView
This is a migrated thread and some comments may be shown as answers.
David Brenchley
Top achievements
Rank 1
David Brenchley asked on 20 Oct 2011, 06:08 PM
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?

5 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 21 Oct 2011, 07:13 AM
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 >>

0
David Brenchley
Top achievements
Rank 1
answered on 24 Oct 2011, 04:10 PM
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.
0
Maya
Telerik team
answered on 25 Oct 2011, 09:18 AM
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 >>

0
David Brenchley
Top achievements
Rank 1
answered on 25 Oct 2011, 03:30 PM
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.
0
Accepted
Maya
Telerik team
answered on 27 Oct 2011, 03:06 PM
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 >>

Tags
GridView
Asked by
David Brenchley
Top achievements
Rank 1
Answers by
Maya
Telerik team
David Brenchley
Top achievements
Rank 1
Share this question
or