Binding Different type of collection to RadTreeView

4 posts, 0 answers
  1. Prakash
    Prakash avatar
    19 posts
    Member since:
    Oct 2010

    Posted 20 Dec 2011 Link to this post

    Hi Everybody,

    Telerik Version: 2010.2.924.1040

    My Requirement:

    I've a collection in the following format and I want to bind the collection to RadTreeView in similar format.
    I've gone many telerik forums links but didn't find anything related to my problem. Since I'm reaching my deadlines I've created a new thread and If you can provide a example then it will be really useful for me. 

    The following is the sample type which is very close to my business object:
    Mobile
    -- ModelName
    -- Price
    + Sims
       -- Sim1
           -- Number
           + Contacts
       -- Sim2 
           -- Number
           + Contacts
    + Folders
        -- FolderName
        + Files
           -- FileName
           -- Size
           -- Capacity
     
    public class Mobile
        {
            public string ModelName { set; get; }
            public string Price { set; get; }
            public ObservableCollection<Sim> Sims { set; get; }
            public ObservableCollection<Folder> Folders { set; get; }
        }


        public class Sim
        {
            public int Number { set; get; }
            public ObservableCollection<Contact> Contacts { set; get; }
        }


        public class Contact
        {
            public string Name { set; get; }
            public string Address { set; get; }
            public int PhoneNumber { set; get; }
        }


        public class Folder
        {
            public string Name { set; get; }
            public ObservableCollection<File> Files { set; get; }
        }


        public class File
        {
            public string FileName { set; get; }
            public string Size { set; get; }
            public string Type { set; get; }
        }

    Thanks,
    Prakash.
  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 23 Dec 2011 Link to this post

    Hello,

     Please check out the File / Folder hierarchy demonstrated in the attached project. In your scenario , you have to unite your Sims and Folders collection in a single collection and differentiate them in the Style/Template Selector logic. Please let us know if you need further assistance on this. 

    Greetings,
    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Prakash
    Prakash avatar
    19 posts
    Member since:
    Oct 2010

    Posted 23 Dec 2011 Link to this post

    Hi Petar Mladenov,

    Thanks for the example, I've gone through example but, In the example the child are belong to same type whereas for me all child will be of different type. 

    Root will show list of Mobiles and each mobile object will contain a list of sim and a list folders, both the sim and folder are of entirely different types. Since I may not specific my business objects here, so, I've specified with some common examples.
    It will be like a node with two or more different types of collections and I may not unit this collection to single collection. Please direct me in doing the above requirement. 

    And my tree structure will look like:

    Mobile 1 
    -- ModelName 
    -- Price
    + Sims 
       -- Sim1
           -- Number
           + Contacts
       -- Sim2 
           -- Number
           + Contacts
    + Folders
        -- FolderName
        + Files
           -- FileName
           -- Size
           -- Capacity

    Mobile 2
    -- ModelName 
    -- Price
    + Sims 
       -- Sim1
           -- Number
           + Contacts
       -- Sim2 
           -- Number
           + Contacts
    + Folders
        -- FolderName
        + Files
           -- FileName
           -- Size
           -- Capacity


    Thanks,
    Prakash.
  5. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 28 Dec 2011 Link to this post

    Hi Prakash,

     The RadTreeView basically represents hierarchical data but in your case you want something different - for example property of an item to behave like its child. When binding the RadTreeView, every hierarchy level needs objects that inherit from one and the same type. That is why in your case you need to make some of the properties and the child items to inherit from common type. I prepared a possible approach for you and you can examine it in the attached solution.
    On a side note, have you considered using a RadTreeListView?

    Kind regards,
    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top