I have objects which contain lists of dynamic and unique Child objects. I would like to pivot the Child objects onto the grid so they display as one row. I have the grid working but I can't quite get the syntax for the binding.
I have an object model like the following:
public class ParentObject
string Name
long ObjectId
List<Child> Children {get; set]
public class Child
string ChildName
string ChildValue
My grid is defined as:
<telerik:RadGridView x:Name="myGrid" Grid.Row="0" VerticalContentAlignment="Stretch" AutoGenerateColumns="False">
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn Header="Name" DataMemberBinding="{Binding Name}" />
<telerik:GridViewDataColumn Header="Object Id" DataMemberBinding="{Binding ObjectId}" />
</telerik:RadGridView.Columns>
In the code behind I dynamically add every possible Child.Name to the grid as new columns.
List<Child> allChildren = _dataAccess.GetChildren();
foreach (Child c in allChildren)
{
myGrid.Columns.Add(
new GridViewBoundColumnBase
{
//DataMemberBinding = new Binding("Children[0].Value"), //this does display the child value but puts it in every column. I can't hardcode the 0
//DataMemberBinding = new Binding("Children[\"" + c.ChildName.Replace(" ","") + "\"].ChildValue"), //tried by child Name but it doesn't bind. To do this I updated my List so it was searchable by Name.
//DataMemberBinding = new Binding("Children.ChildValue"), Does not work
Name = c.Name.Replace(" ", ""),
Header = c.Name
});
}
All of the correct columns display, I just need to know if it is possible to do a match on the ParentObject.Children.Name to a column so the grid can display the ChildValue field.
A Linq statement similar to Where(x => x.name = column name) I would think would work if that is possible in a Binding.
I have an object model like the following:
public class ParentObject
string Name
long ObjectId
List<Child> Children {get; set]
public class Child
string ChildName
string ChildValue
My grid is defined as:
<telerik:RadGridView x:Name="myGrid" Grid.Row="0" VerticalContentAlignment="Stretch" AutoGenerateColumns="False">
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn Header="Name" DataMemberBinding="{Binding Name}" />
<telerik:GridViewDataColumn Header="Object Id" DataMemberBinding="{Binding ObjectId}" />
</telerik:RadGridView.Columns>
In the code behind I dynamically add every possible Child.Name to the grid as new columns.
List<Child> allChildren = _dataAccess.GetChildren();
foreach (Child c in allChildren)
{
myGrid.Columns.Add(
new GridViewBoundColumnBase
{
//DataMemberBinding = new Binding("Children[0].Value"), //this does display the child value but puts it in every column. I can't hardcode the 0
//DataMemberBinding = new Binding("Children[\"" + c.ChildName.Replace(" ","") + "\"].ChildValue"), //tried by child Name but it doesn't bind. To do this I updated my List so it was searchable by Name.
//DataMemberBinding = new Binding("Children.ChildValue"), Does not work
Name = c.Name.Replace(" ", ""),
Header = c.Name
});
}
All of the correct columns display, I just need to know if it is possible to do a match on the ParentObject.Children.Name to a column so the grid can display the ChildValue field.
A Linq statement similar to Where(x => x.name = column name) I would think would work if that is possible in a Binding.