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

How to deselect a row when it is clicked

2 Answers 154 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Geoff Hardy
Top achievements
Rank 1
Geoff Hardy asked on 04 Aug 2010, 09:54 PM
I have a RadGridView where I would like the following behavior:
- only 1 or 0 rows can be selected at any given time
- if I click on a row that is unselected, the row will become the only row selected
- if I click on a row that is already selected, the row will become deselected

This type of selection seems to be somewhere between the Single SelectionMode (in that only one row can be selected at once) and the Multiple SelectionMode (in that a row can be deselected by clicking on it).

Is there an easy/clean way to do this?

2 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 09 Aug 2010, 03:46 PM
Hello Geoff Hardy,

Here is what you can do - set the SelectionMode to Multiple and subscribe to the SelectionChanged event and define its handler as follows:

private void clubsGrid_SelectionChanged(object sender, SelectionChangeEventArgs e)
{
    if (clubsGrid.SelectedItems.Count > 1)
    {
        Club latestAddedItem = e.AddedItems[0] as Club;
        clubsGrid.SelectedItems.Clear();
        clubsGrid.SelectedItems.Add(latestAddedItem);
    }
}

Hope this helps.

All the best,
Veselin Vasilev
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Geoff Hardy
Top achievements
Rank 1
answered on 09 Aug 2010, 04:25 PM
Thanks Veselin, that did the trick!
Tags
GridView
Asked by
Geoff Hardy
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Geoff Hardy
Top achievements
Rank 1
Share this question
or