Databind collections of disparate types

2 posts, 0 answers
  1. MartinM
    MartinM avatar
    3 posts
    Member since:
    Dec 2009

    Posted 11 Sep 2014 Link to this post

    Hi,
    I am able to successfully bind hierarchical data with two levels (for example, "Categories\Products"), but I would like to databind 3 different collections of different types, the result being something like:

    +Categories
        CategoryA
        CategoryB
    +Products
        Product1
        Product2
    +Location
        LocationX
        LocationY

    where

    public IList<Category> Categories { get; set; }
    public IList<Product> Products  { get; set; }
    public IList<Location> Locations  { get; set; }


    Similar to this question: http://www.telerik.com/forums/treeview-binding-to-multiple-object-types-in-mvvm

    Aside from 'selecting' each item into a new common type, is there a better way to do this?

    Thanks for your input,



  2. Dimitar
    Admin
    Dimitar avatar
    1408 posts

    Posted 16 Sep 2014 Link to this post

    Hi Martin,

    Thank you for writing.

    In this case you cannot directly bind the treeview to the datasource object. However you can use the load on demand feature and manually populate the nodes. The attached project contains sample implementation of this approach. 

    I hope this will be useful.

    Regards,
    Dimitar
    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.
     
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top