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

How to allow only a single selected row in a hierarchy

5 Answers 255 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 24 Mar 2011, 11:20 PM
Using a hierarchy view similar to the Custom Hierarchy demo, I want to allow the user to select only a single row of data (regardless of what tier that data is at). Further, I want to be able to bind to the currently selected row. I saw the demo on how to do this with a single-tier gridview which seems to get me halfway there - I just need to further extend that to the children as well.

5 Answers, 1 is accepted

Sort by
0
Andrew
Top achievements
Rank 1
answered on 25 Mar 2011, 04:51 PM
I found out how to do half of this... If I bind the SelectedItem property of the child gridview to the ancestor RadGridView's SelectedItem property (TwoWay) SelectedItem will change whenever I click on any of the RadGridView rows to either the parent or child data.
However, visually it appers that there are multiple rows selected (one in each RadGridView that's ever been clicked). How can I fix this so that when the SelectedItem is changed it will unselect what was previously highlighted?
0
Pavel Pavlov
Telerik team
answered on 30 Mar 2011, 12:03 PM
Hello Andrew,

I have tried to find a solution with bindings only for your scenario.However the only solution I can think of would require the following :

1.Provide a helper class to manage the selection of al RadGridView controls parent and child.
2.When a GridView is loaded this class should subscribe to selection changed events and take care to set unset selection in all managed control so that only one has active selection at the moment.

This involves handling two event s - the Loaded and the Selection changed event of all instances of RadGridView.

In case this approach is suitable to your scenario I can prepare a small sample for you if needed.

Regards,
Pavel Pavlov
the Telerik team
0
Andrew
Top achievements
Rank 1
answered on 30 Mar 2011, 03:40 PM
That would work and is along the lines of one possible solution I was considering - inheriting from RadGridView to inject this custom behavior (when SelectedItem is changed if the NewValue isn't part of the current ItemsSource it would unset all rows). I would really appreciate a sample showing how to do it your way, though!
1
Milan
Telerik team
answered on 05 Apr 2011, 09:54 AM

Hi Andrew,

Here is a sample project that demonstrates one possible solution.

Hope it helps.



Kind regards,
Milan
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
Andrew
Top achievements
Rank 1
answered on 05 Apr 2011, 03:56 PM
That seems to work great - thanks!
Tags
GridView
Asked by
Andrew
Top achievements
Rank 1
Answers by
Andrew
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Milan
Telerik team
Share this question
or