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

Hierarchical Grid View - Keep style, context menu, etc

8 Answers 167 Views
GridView
This is a migrated thread and some comments may be shown as answers.
JDT
Top achievements
Rank 1
JDT asked on 14 Jun 2010, 10:12 PM
Hi Telerik,

I have a gridview that has the look, columns setup, context menu and more , all setup the way I want. What I need is to view child items in a child gridview where the columns, context menu, functionality etc, are the same like the parent grid. My object model (shortened for this example) is as follows.

I would also like to add other controls to the details view in the future. I have read other posts and have tried using a <dataTemplate> with another gridview but could not get the relation property to populate the child gridview. Not to mention I have to manage 2 gridviews instead of one. What's the best way to approach this? 

I also noticed that when there are no children objects, the parent row still has a "+" sign which then opens up the child grid with no items in it. Is there a way to turn this off?

Thanks! 

public class Person 
string name; 
datetime dob; 
char gender; 
List<Person> children; 
 
<telerikGridView:RadGridView> 
            <telerikGridView:RadGridView.ChildTableDefinitions> 
                <telerikGridView:GridViewTableDefinition> 
                    <telerikGridView:GridViewTableDefinition.Relation> 
                        <telerikData:PropertyRelation ParentPropertyName="children" /> 
                    </telerikGridView:GridViewTableDefinition.Relation> 
                </telerikGridView:GridViewTableDefinition> 
            </telerikGridView:RadGridView.ChildTableDefinitions> 
            <telerikGridView:RadGridView.Columns> 
                    <telerikGridView:GridViewSelectColumn/> 
                    <telerikGridView:GridViewDataColumn DataMemberBinding="{Binding name}" Header="Name" /> 
                    <telerikGridView:GridViewDataColumn DataMemberBinding="{Binding dob}" Header="dob"  /> 
                    <telerikGridView:GridViewDataColumn DataMemberBinding="{Binding gender}" Header="Gender" /> 
                </telerikGridView:RadGridView.Columns> 
            <telerikNavigation:RadContextMenu.ContextMenu> 
                <telerikNavigation:RadContextMenu x:Name="contextMenuGrid" Opened="contextMenuGrid_Opened"
                    <telerikNavigation:RadContextMenu.Items> 
                        <telerikNavigation:RadMenuItem Header="Delete" Click="Delete_Click"/> 
                    </telerikNavigation:RadContextMenu.Items> 
                </telerikNavigation:RadContextMenu> 
            </telerikNavigation:RadContextMenu.ContextMenu> 
        </telerikGridView:RadGridView> 

8 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 15 Jun 2010, 06:24 AM
Hi,

You can use style to define desired common properties for both grids. Since you have PropertyRelation you can safely remove this and use simple Binding for your child grid ItemsSource (and indeed declare your child grid in HIerachyChildTemplate)

... ItemsSource="{Binding children}" ...

Best wishes,
Vlad
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
JDT
Top achievements
Rank 1
answered on 15 Jun 2010, 05:58 PM
Wouldn't I have to create a new  child grid and re-specify the column definitions and re-create yet another context menu control with all the handlers pointing to the existing handlers? A sample would be great if you have one.

Thanks!
0
Veselin Vasilev
Telerik team
answered on 18 Jun 2010, 12:56 PM
Hi JDT,

The context menu that you defined in the parent grid will show when you right click on the child grid as well so you do not have to create another context menu.

And yes, you need to create the columns by yourself if you do not want them to be autogenerated.
Here is a simple gridview definition:

<telerik:RadGridView Name="gridView" >
<telerik:RadContextMenu.ContextMenu>
    <telerik:RadContextMenu Opened="RadContextMenu_Opened" ItemClick="RadContextMenu_ItemClick">
        <telerik:RadContextMenu.Items>
            <telerik:RadMenuItem Header="Add" />
            <telerik:RadMenuItem Header="Edit" />
            <telerik:RadMenuItem Header="Delete" />
        </telerik:RadContextMenu.Items>
    </telerik:RadContextMenu>
</telerik:RadContextMenu.ContextMenu>
<telerik:RadGridView.ChildTableDefinitions>
    <telerik:GridViewTableDefinition>
        <telerik:GridViewTableDefinition.Relation>
            <telerik:PropertyRelation ParentPropertyName="Children" ></telerik:PropertyRelation>
        </telerik:GridViewTableDefinition.Relation>
    </telerik:GridViewTableDefinition>
</telerik:RadGridView.ChildTableDefinitions>
<telerik:RadGridView.HierarchyChildTemplate>
    <DataTemplate>
        <telerik:RadGridView ItemsSource="{Binding Children}" />
    </DataTemplate>
</telerik:RadGridView.HierarchyChildTemplate>
</telerik:RadGridView>

Hope this helps.

Regards,
Veskoni
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
JDT
Top achievements
Rank 1
answered on 28 Feb 2011, 06:00 PM
This post is a little old but still having problems with the above now that we are using row details. One problem is when right clicking a row in a row details grid the row details grid dissapears (collpases back). Also the selected row reported in the handler isn't always correct. Tried using 2 contextmenu controls one in each grid, tried the above and it isn't working.

I need a sample with a grid, row details, same context menu that can be used on both main/detail rows, where events fired get the correct selected row, column binding to properties and a simple c# object. Prefer not to have static content or databound services.

Appreciate it!
0
Priya
Top achievements
Rank 1
answered on 30 Oct 2013, 06:38 PM
Can we either not show the Rad Context menu or show a different contect menu in the child hierarchical grid ?

Thanks
Priya
0
Priya
Top achievements
Rank 1
answered on 30 Oct 2013, 06:39 PM
Can we either not show the Rad Context menu or show a different contect menu in the child hierarchical grid ?

Thanks
Priya
0
Maya
Telerik team
answered on 04 Nov 2013, 08:30 AM
Hello Priya,

You can handle Opening event of RadContextMenu, verify what is the clicked item and cancel it when required:

private void RadContextMenu_Opening(object sender, Telerik.Windows.RadRoutedEventArgs e)
        {
            var menu = sender as RadContextMenu;
            var clickedRow = menu.GetClickedElement<GridViewRow>();
 
            if (clickedRow != null && clickedRow.Item is Player)
            {
                e.Handled = true;
            }
        }
 

Regards,
Maya
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Priya
Top achievements
Rank 1
answered on 04 Nov 2013, 03:42 PM
Thanks Maya. Works as needed.
Tags
GridView
Asked by
JDT
Top achievements
Rank 1
Answers by
Vlad
Telerik team
JDT
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Priya
Top achievements
Rank 1
Maya
Telerik team
Share this question
or