Help? CustomRelationalHierarchy example with Custom Grid View Template

5 posts, 0 answers
  1. Andy
    Andy avatar
    11 posts
    Member since:
    Feb 2009

    Posted 17 Apr 2009 Link to this post

    Hi

    I've been looking at the CustomRelationalHierarchy example shipping with the current SL controls. Now the example shows how to have a child grid whith a property collection that is automatically generated. I was hoping someone has an example of how to use this with a HierarchyChildTemplate defined in XAML so instead of an auto generated grid I want to create custom columns that are bound to my ChildTableDefinitions data source? My problem is I'm struggling to understand how the DataBinding hierachy works with this so I can bind my GridView in the HierarchyChildTemplate to my sub collecton.

    Thanks

    Andy
  2. Andrew
    Andrew avatar
    26 posts
    Member since:
    Apr 2009

    Posted 19 Apr 2009 Link to this post

    Hi Andy,


    I hope this helps... A fair bit of this is just customisations and isn't required

            <telerik:RadGridView x:Name="ProductDataGrid"   
                                 Height="550"                               
                                 AutoGenerateColumns="False" 
                                 Style="{StaticResource RadGridViewStyle}" 
                                 CanUserFreezeColumns="False" 
                                 IsFilteringAllowed="False"                                                             
                                 ShowGroupPanel="False" 
                                 MultipleSelect="True"
     
                <telerik:RadGridView.Columns> 
                    <telerik:GridViewDataColumn HeaderText="Name" DataMemberPath="Name" Width="30*" /> 
                    <telerik:GridViewDataColumn HeaderText="Description" DataMemberPath="Description" Width="70*" /> 
                </telerik:RadGridView.Columns> 
                <telerik:RadGridView.HierarchyChildTemplate> 
                    <DataTemplate> 
                        <StackPanel> 
                            <telerik:RadGridView Width="800"                                                                                            
                                                 CanUserReorderColumns="False" 
                                                 CanUserFreezeColumns="False"                                                                                              
                                                 ShowGroupPanel="False" 
                                                 Margin="20" 
                                                 IsFilteringAllowed="False"                                           
                                                 > 
     
                            </telerik:RadGridView> 
                        </StackPanel> 
                    </DataTemplate> 
                </telerik:RadGridView.HierarchyChildTemplate> 
            </telerik:RadGridView> 


    There was another example supplied by Telerik which I used as a basis for the following code, but I can't remember it off the top of my head

            void ProductDataGrid_Loaded(object sender, RoutedEventArgs e) 
            { 
                GridViewTableDefinition detailDefinition = new GridViewTableDefinition(); 
                detailDefinition.Relation = new PropertyRelation("Specification"); 
                detailDefinition.AutoGenerateFieldDescriptors = false
     
                GridViewDataColumn column = new GridViewDataColumn(); 
                column.DataMemberBinding = new Binding("ShortName"); 
                column.HeaderText = "Abbr"
                column.DataType = typeof(string); 
                detailDefinition.FieldDescriptors.Add(column); 
     
     
                column = new GridViewDataColumn(); 
                column.DataMemberBinding = new Binding("LongName"); 
                column.HeaderText = "Name"
                column.DataType = typeof(string); 
                detailDefinition.FieldDescriptors.Add(column); 
     
    ... etc ... 
     
                ProductDataGrid.TableDefinition.ChildTableDefinitions.Add(detailDefinition); 
     
                ProductDataGrid.ItemsSource = productList; 
     
            } 

    I have a ObservableCollection called "productList" of type "Product"

    For a "Product", there are two properties, which are "Name" and "Description". These are displayed through XAML

    Also inside "Product" is property called "Specification", which is a list of "ProductDetails"

    Inside "ProductDetails" I have "ShortName" and "LongName". These are displayed through the code behind in C#

    I hope this explanation matches up against the code I have supplied above

    Good luck

  3. Andy
    Andy avatar
    11 posts
    Member since:
    Feb 2009

    Posted 19 Apr 2009 Link to this post

    Hi Andrew

    Thanks for the reply, it's appreciated but it's not quite what I was hoping for :-). I managed to get to the same point but what I would like to do is define the columns in the xaml so I can customise them so in your example I'd like the ShortName and the LongName columns in the .xaml page and not define them in code. When I try this I seem to hit issues with the databinding as it apprears the GridView wraps the datacontext in it's own type and I can't seem to get it to behave.
  4. Andrew
    Andrew avatar
    26 posts
    Member since:
    Apr 2009

    Posted 19 Apr 2009 Link to this post

    No worries

    I had similar issues and couldn't work it out. Hopefully we will get a response soon
  5. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 22 Apr 2009 Link to this post

    Hi guys,

    Please excuse us for the inconvenience caused.  I have investigated  the issue. There is definitely a bug in the RadGridView preventing  the child grid to contain customized rather than autogenerated columns.
    The child grids automatically get a full set of autogenerated columns disregarding any XAML declared columns.

    We have already started fixing this. Meanwhile I  have prepared a sample with a workaround approach.
    Please find it  attached.

    What is important in the example :
    The following code :

     

    <StackPanel DataContext="{x:Null}">

     

     

     

     

        <telerik:RadGridView ...

     

    ...

     

     

     

     

    prevents the child RadGridView to get the automatic columns.

    and the following lines bypass the "auto" logic and feeds the child grid with data:

    In code behind:

    private void RadGridView_Loaded(object sender, RoutedEventArgs e)

    {

    ((RadGridView) sender).DataContext = ((RadGridView) sender).ParentRow.DataContext;

    }

    ...

    And in xaml :
    <

    telerik:RadGridView Width="200" Loaded="RadGridView_Loaded" ItemsSource="{Binding Staff}"  ...


    This way the child grid now respects the two declarative columns in the HierarchyChildTemplate.


    If you need any help on customizing the example for your needs just let me know.  Meanwhile we are doing our best to fix the problem.

    Kind regards,
    Pavel Pavlov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top