How do I get the selected Item in a HierarchyChildTemplate

2 posts, 0 answers
  1. ScopiaRx_CTO
    ScopiaRx_CTO avatar
    9 posts
    Member since:
    Aug 2007

    Posted 21 Jun 2010 Link to this post

    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.


  2. Yavor Georgiev
    Yavor Georgiev avatar
    982 posts

    Posted 21 Jun 2010 Link to this post

    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
Back to Top