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
4 Answers, 1 is accepted
0
Andrew
Top achievements
Rank 1
answered on 19 Apr 2009, 12:38 PM
Hi Andy,
I hope this helps... A fair bit of this is just customisations and isn't required
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
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
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
0
Andy
Top achievements
Rank 1
answered on 19 Apr 2009, 02:40 PM
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.
0
Andrew
Top achievements
Rank 1
answered on 19 Apr 2009, 10:59 PM
No worries
I had similar issues and couldn't work it out. Hopefully we will get a response soon
I had similar issues and couldn't work it out. Hopefully we will get a response soon
0
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 :
and the following lines bypass the "auto" logic and feeds the child grid with data:
In code behind:
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.
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.