I am writing a WPF application using MVVM, I am trying to bind a nested complex object to the telerik radGridView control. I basically need to create the datagrid dynamically and I only know at run time how many columns it will have also the columns need to be generated from the rows...
The MetaDataDO class,
public class MetaDataDO
{
public int MetaItemId { get; set; }
public string Name { get; set; }
public int SequenceNumber { get; set; }
public IList<ItemDO> Volumes { get; set; }
}
The ItemDO class,
public class ItemDO
{
public int ItemId { get; set; }
public DateTime StartDateTime { get; set; }
public DateTime EndDateTime { get; set; }
public int Period { get; set; }
public decimal Price { get; set; }
}
In my view model I have a property ObservableCollection MetaDataCollection that can have N number of MetaDataDO, each MetaDataDO will have 4 Prices in it. Example data below..
MetaDataCollection
1, UK, 10,
Volumes
1, 24/01/2014 00:00, 24/01/2014 06:00, 1, 100
2, 24/01/2014 06:00, 24/01/2014 12:00, 2, 120
3, 24/01/2014 12:00, 24/01/2014 18:00, 3, 110
4, 24/01/2014 18:00, 24/01/2014 24:00, 4, 150
2, UAE, 20,
Volumes
1, 24/01/2014 00:00, 24/01/2014 06:00, 1, 500
2, 24/01/2014 06:00, 24/01/2014 12:00, 2, 140
3, 24/01/2014 12:00, 24/01/2014 18:00, 3, 510
4, 24/01/2014 18:00, 24/01/2014 24:00, 4, 550
.... can have N more...
I have no control over how these existing objects are defined, these are being returned by an external system. Once I receive the data in my viewmodel,
I want to display the results on the UI in the radGridView in the following format,
Start | End | UK | USA
--------------------------------------------------------------------
24/01/2014 00:00 | 24/01/2014 06:00 | 100 | 500
24/01/2014 06:00 | 24/01/2014 12:00 | 120 | 140
24/01/2014 12:00 | 24/01/2014 18:00 | 110 | 510
24/01/2014 18:00 | 24/01/2014 24:00 | 150 | 550
so in simple terms, i am trying to bind the property to the radGridView in the following way...
Start | End | UK | USA
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
MetaDataCollection[0].Volumes[0].Start | MetaDataCollection[0].Volumes[0].End | MetaDataCollection[0].Volumes[0].Price | MetaDataCollection[1].Volumes[0].Price
MetaDataCollection[0].Volumes[1].Start | MetaDataCollection[0].Volumes[1].End | MetaDataCollection[0].Volumes[1].Price | MetaDataCollection[1].Volumes[1].Price
MetaDataCollection[0].Volumes[2].Start | MetaDataCollection[0].Volumes[2].End | MetaDataCollection[0].Volumes[2].Price | MetaDataCollection[1].Volumes[2].Price
MetaDataCollection[0].Volumes[3].Start | MetaDataCollection[0].Volumes[3].End | MetaDataCollection[0].Volumes[3].Price | MetaDataCollection[1].Volumes[3].Price
How do I bind the property which is really a complex nested object to the radGridView to achieve this output format? Any hints welcome...
Thanks
Tarun
The MetaDataDO class,
public class MetaDataDO
{
public int MetaItemId { get; set; }
public string Name { get; set; }
public int SequenceNumber { get; set; }
public IList<ItemDO> Volumes { get; set; }
}
The ItemDO class,
public class ItemDO
{
public int ItemId { get; set; }
public DateTime StartDateTime { get; set; }
public DateTime EndDateTime { get; set; }
public int Period { get; set; }
public decimal Price { get; set; }
}
In my view model I have a property ObservableCollection MetaDataCollection that can have N number of MetaDataDO, each MetaDataDO will have 4 Prices in it. Example data below..
MetaDataCollection
1, UK, 10,
Volumes
1, 24/01/2014 00:00, 24/01/2014 06:00, 1, 100
2, 24/01/2014 06:00, 24/01/2014 12:00, 2, 120
3, 24/01/2014 12:00, 24/01/2014 18:00, 3, 110
4, 24/01/2014 18:00, 24/01/2014 24:00, 4, 150
2, UAE, 20,
Volumes
1, 24/01/2014 00:00, 24/01/2014 06:00, 1, 500
2, 24/01/2014 06:00, 24/01/2014 12:00, 2, 140
3, 24/01/2014 12:00, 24/01/2014 18:00, 3, 510
4, 24/01/2014 18:00, 24/01/2014 24:00, 4, 550
.... can have N more...
I have no control over how these existing objects are defined, these are being returned by an external system. Once I receive the data in my viewmodel,
I want to display the results on the UI in the radGridView in the following format,
Start | End | UK | USA
--------------------------------------------------------------------
24/01/2014 00:00 | 24/01/2014 06:00 | 100 | 500
24/01/2014 06:00 | 24/01/2014 12:00 | 120 | 140
24/01/2014 12:00 | 24/01/2014 18:00 | 110 | 510
24/01/2014 18:00 | 24/01/2014 24:00 | 150 | 550
so in simple terms, i am trying to bind the property to the radGridView in the following way...
Start | End | UK | USA
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
MetaDataCollection[0].Volumes[0].Start | MetaDataCollection[0].Volumes[0].End | MetaDataCollection[0].Volumes[0].Price | MetaDataCollection[1].Volumes[0].Price
MetaDataCollection[0].Volumes[1].Start | MetaDataCollection[0].Volumes[1].End | MetaDataCollection[0].Volumes[1].Price | MetaDataCollection[1].Volumes[1].Price
MetaDataCollection[0].Volumes[2].Start | MetaDataCollection[0].Volumes[2].End | MetaDataCollection[0].Volumes[2].Price | MetaDataCollection[1].Volumes[2].Price
MetaDataCollection[0].Volumes[3].Start | MetaDataCollection[0].Volumes[3].End | MetaDataCollection[0].Volumes[3].Price | MetaDataCollection[1].Volumes[3].Price
How do I bind the property which is really a complex nested object to the radGridView to achieve this output format? Any hints welcome...
Thanks
Tarun