Telerik WPF radGridView dynamic columns from complex nested object

3 posts, 0 answers
  1. Tarun
    Tarun avatar
    6 posts
    Member since:
    Jan 2012

    Posted 25 Jan 2014 Link to this post

    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
















  2. Kevin
    Kevin avatar
    15 posts
    Member since:
    Feb 2014

    Posted 02 Jul 2014 in reply to Tarun Link to this post

    Did you ever come up with a solution to this issue?  I have the exact same problem and I have not found a good answer.

    Thanks!
  3. UI for WPF is Visual Studio 2017 Ready
  4. Nick
    Admin
    Nick avatar
    593 posts

    Posted 04 Jul 2014 Link to this post

    Hi Tarun,

    This is still an issue when binding to a dynamic object. You can try working around it with custom CellTemplates (<TextBlock Text={Binding DynamicObject["Property"].Values[0]}>).


    Regards,
    Nik
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top