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

Context Menu for HierarchyChildTemplate GridView

7 Answers 283 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Greg
Top achievements
Rank 1
Greg asked on 16 Oct 2012, 07:07 PM
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

7 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 17 Oct 2012, 07:25 AM
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.

0
Greg
Top achievements
Rank 1
answered on 17 Oct 2012, 01:45 PM
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. 
0
Dimitrina
Telerik team
answered on 18 Oct 2012, 01:35 PM
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.

0
Greg
Top achievements
Rank 1
answered on 18 Oct 2012, 02:27 PM
Thanks Didie. I will take a look at it and let you know.

Cheers.
0
Princee
Top achievements
Rank 1
answered on 06 Aug 2014, 12:00 PM
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?




0
Dimitrina
Telerik team
answered on 06 Aug 2014, 01:01 PM
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.
 
0
Princee
Top achievements
Rank 1
answered on 07 Aug 2014, 05:36 AM
hi,
    I apologize for posting question under wrong product category.I have moved it under respective category.


Thanks
Tags
GridView
Asked by
Greg
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Greg
Top achievements
Rank 1
Princee
Top achievements
Rank 1
Share this question
or