Hierarchical Grid View - Keep style, context menu, etc

9 posts, 0 answers
  1. JDT
    JDT avatar
    45 posts
    Member since:
    Jul 2007

    Posted 14 Jun 2010 Link to this post

    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> 

  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 15 Jun 2010 Link to this post

    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.
  3. DevCraft banner
  4. JDT
    JDT avatar
    45 posts
    Member since:
    Jul 2007

    Posted 15 Jun 2010 Link to this post

    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!
  5. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 18 Jun 2010 Link to this post

    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
  6. JDT
    JDT avatar
    45 posts
    Member since:
    Jul 2007

    Posted 28 Feb 2011 Link to this post

    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!
  7. Priya
    Priya avatar
    7 posts
    Member since:
    Nov 2012

    Posted 30 Oct 2013 Link to this post

    Can we either not show the Rad Context menu or show a different contect menu in the child hierarchical grid ?

    Thanks
    Priya
  8. Priya
    Priya avatar
    7 posts
    Member since:
    Nov 2012

    Posted 30 Oct 2013 Link to this post

    Can we either not show the Rad Context menu or show a different contect menu in the child hierarchical grid ?

    Thanks
    Priya
  9. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 04 Nov 2013 Link to this post

    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 >>
  10. Priya
    Priya avatar
    7 posts
    Member since:
    Nov 2012

    Posted 04 Nov 2013 Link to this post

    Thanks Maya. Works as needed.
Back to Top
DevCraft banner