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

How do I get the selected Item in a HierarchyChildTemplate

1 Answer 107 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
ScopiaRx_CTO asked on 21 Jun 2010, 02:12 PM
I have a HierarchyChileTemplte defined as...














<telerikGridView:RadGridView x:Name="RadGridView_Prospect" CanUserFreezeColumns="False" AutoGenerateColumns="False" ItemsSource="{Binding Prospects}"




ShowGroupPanel="False" IsReadOnly="True" AlternationCount="2" AlternateRowBackground="Azure" SelectionMode="Single">










<telerikGridView:GridViewDataColumn DataMemberBinding="{Binding Id}" Header="ID" IsFilterable="False" Width="64" />





<telerikGridView:GridViewDataColumn DataMemberBinding="{Binding FirstName}" Header="First Name" IsFilterable="False" Width="128" />





<telerikGridView:GridViewDataColumn DataMemberBinding="{Binding LastName}" Header="Last Name" IsFilterable="False" Width="128" />





<telerikGridView:GridViewDataColumn DataMemberBinding="{Binding Title}" Header="Title" IsFilterable="False" Width="96" />





















and I have a button elsewhere on the form.  When the user clicks the button i want to be able to access the SelectedItem in the Child Grid but .SelectedItem on the ParentGrid is null and I cannot figure out how to reference the Child Grid from code since x:Name does not make it accessible to code behind nor can I just change x:Name to Name apparently.  This does not appear to be an issue when the user double clicks on an Item in the Child Grid since that seems to bubble up to the parent, but SelectedItem does not get set on a single click.


1 Answer, 1 is accepted

Sort by
Yavor Georgiev
Telerik team
answered on 21 Jun 2010, 02:40 PM
Hello WS-SQL,

 If you attach an event handler to the parent's SelectionChanged event, it should be called whenever the child's SelectionChanged event fires, too.

You can access the child grid from anywhere (for instance, a button click handler), like so:

var childGrids = this.parentGrid.ChildrenOfType<GridViewDataControl>();

Then you can very easily get the selected item:
var item = childGrids[0].SelectedItem;

Yavor Georgiev
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
Asked by
Top achievements
Rank 1
Answers by
Yavor Georgiev
Telerik team
Share this question