Context Menu for HierarchyChildTemplate GridView

8 posts, 0 answers
  1. Greg
    Greg avatar
    7 posts
    Member since:
    Oct 2012

    Posted 16 Oct 2012 Link to this post

    I have a GridView with a HierarchyChildTemplate that has a Grid View. I need a context menu in that ChildTemplate GridView that sees things on the View Model. How do I get it to see the viewmodel for the proper binding?

    Code:

    <telerik:RadGridView Grid.Row="0"
                                 x:Name="radGridView"
                                 ItemsSource="{Binding Items}"
                                 AutoGenerateColumns="False"
                                 SelectionMode="Extended"
                                 SelectionUnit="FullRow"
                                 ShowGroupPanel="False"
                                 Margin="25,25,25,25"
                                 ui:MultiSelectorBehaviours.SynchronizedSelectedItems="{Binding Path=SelectedItems}"
                                 AllowDrop="True"
                                 IsFilteringAllowed="True">
                <telerik:RadGridView.ChildTableDefinitions>
                    <telerik:GridViewTableDefinition/>
                </telerik:RadGridView.ChildTableDefinitions>
                <telerik:RadGridView.HierarchyChildTemplate>
                    <DataTemplate>
                        <telerik:RadGridView ItemsSource="{Binding ProjectionTasksLink}"
                                             AutoGenerateColumns="False"
                                             SelectionMode="Extended"
                                             SelectionUnit="FullRow"
                                             ShowGroupPanel="False"        
                                             AllowDrop="True">
                            <telerik:RadGridView.Columns>
                                <telerik:GridViewDataColumn Header="Projection"
                                                            UniqueName="Name"
                                                            DataMemberBinding="{Binding}"
                                                            CellTemplate="{StaticResource CellTemplate.TaskName}"
                                                            IsReadOnly="True"/>
                                <telerik:GridViewDataColumn Header="Run Parameter Set"
                                                            UniqueName="RunParametersLink"
                                                            DataMemberBinding="{Binding}"
                                                            CellTemplate="{StaticResource CellTemplate.RunParameterSetName}"
                                                            IsReadOnly="True"/>
                            </telerik:RadGridView.Columns>
                            <telerik:RadGridView.ContextMenu>
                                <ContextMenu>
                                    <MenuItem Header="Run Selected Item(s)"
                                             DataContext="{Binding Path=PlacementTarget.DataContext, RelativeSource={RelativeSource AncestorType=ContextMenu}}"
                                             Command="{Binding RunAllSelectedTasksCommand}"
                                             CommandParameter="{Binding Path=PlacementTarget.SelectedContexts, RelativeSource={RelativeSource AncestorType=ContextMenu}, Converter={StaticResource runControllerJobCmdConverter}}">
                                        <MenuItem.Icon>
                                            <Image Source="Images/Run16.png" />
                                        </MenuItem.Icon>
                                    </MenuItem>
                                </ContextMenu>
                            </telerik:RadGridView.ContextMenu>
                        </telerik:RadGridView>
                    </DataTemplate>
                </telerik:RadGridView.HierarchyChildTemplate>
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn Header="Run Page Name"
                                                UniqueName="Name"
                                                CellTemplate="{StaticResource CellTemplate.RunPageName}"
                                                DataMemberBinding="{Binding}"
                                                IsReadOnly="True"/>
                    <telerik:GridViewDataColumn Header="Target Model Object"
                                                UniqueName="AssociatedTargetModelObjectLink"
                                                DataMemberBinding="{Binding}"
                                                CellTemplate="{StaticResource CellTemplate.TargetModelObjectName}"
                                                IsReadOnly="True"/>
                    <telerik:GridViewDataColumn Header="InputManager"
                                                UniqueName="AssociatedInputManagerLink"
                                                CellTemplate="{StaticResource CellTemplate.InputManagersList}"
                                                DataMemberBinding="{Binding}"
                                                IsReadOnly="True"/>
                </telerik:RadGridView.Columns>
                <telerik:RadGridView.ContextMenu>
                    <ContextMenu>
                        <MenuItem Header="Run Selected Item(s)"
                                 DataContext="{Binding Path=PlacementTarget.DataContext, RelativeSource={RelativeSource AncestorType=ContextMenu}}"
                                 Command="{Binding RunAllSelectedTasksCommand}"
                                 CommandParameter="{Binding Path=PlacementTarget.SelectedContexts, RelativeSource={RelativeSource AncestorType=ContextMenu}, Converter={StaticResource runControllerJobCmdConverter}}">
                            <MenuItem.Icon>
                                <Image Source="Images/Run16.png" />
                            </MenuItem.Icon>
                        </MenuItem>
                    </ContextMenu>
                </telerik:RadGridView.ContextMenu>
            </telerik:RadGridView>

    The context menu in the parent grid is fine, but the one in the nested grid is not right.

    Side question. Is there a better way to do the nested grid thing than the HierachyTemplate? I would like for this to be one grid that does nesting. I tried using 
    ChildTableDefinitions, but I can't specify things like columns and what not.

    Thanks,
    Greg
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 17 Oct 2012 Link to this post

    Hello,

    Please keep in mind that the DataContext of the hierarchy is the bound data item, not the DataContext of the parent GridView. So you could specify a valid source (the ViewModel) using a StaticResource. Does this help?

    Regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. Greg
    Greg avatar
    7 posts
    Member since:
    Oct 2012

    Posted 17 Oct 2012 Link to this post

    I need the datacontext of the parent grid for the context menu of the child grid. I guess I am asking how I can do that. 
  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 18 Oct 2012 Link to this post

    Hello,

    I have attached a sample project to show you what I mean. In the test project I have bound the Header for the MenuItem to the SelectedItem object in the ViewModel, so when the ContextMenu is shown the Name of the selected item will be displayed.

    I hope you can apply this into your solution.

    Kind regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  5. Greg
    Greg avatar
    7 posts
    Member since:
    Oct 2012

    Posted 18 Oct 2012 Link to this post

    Thanks Didie. I will take a look at it and let you know.

    Cheers.
  6. Princee
    Princee avatar
    7 posts
    Member since:
    Feb 2012

    Posted 06 Aug 2014 Link to this post

    Hi
        I have RadContextMenu with hidden and non-hidden menu items  on RadTreeView . Add menu item to the tree .Open context menu ,It is showing  all the menu items which are marked as hidden.After debugging I found RadContextMenu  datacontext is becoming null.It is working fine when I'm explicitly setting datacontext .


    Is this control issue?




  7. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 06 Aug 2014 Link to this post

    Hello,

    This topic is about RadGridView. As you have a problem with RadContextMenu on RadTreeView, I would suggest you to post your question under the respective product category.

    Regards,
    Didie
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  8. Princee
    Princee avatar
    7 posts
    Member since:
    Feb 2012

    Posted 07 Aug 2014 in reply to Dimitrina Link to this post

    hi,
        I apologize for posting question under wrong product category.I have moved it under respective category.


    Thanks
Back to Top