This is a migrated thread and some comments may be shown as answers.

Binding Different type of collection to RadTreeView

3 Answers 89 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Prakash
Top achievements
Rank 1
Prakash asked on 20 Dec 2011, 05:08 PM
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.

3 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 23 Dec 2011, 03:25 PM
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 >>

0
Prakash
Top achievements
Rank 1
answered on 23 Dec 2011, 03:46 PM
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.
0
Petar Mladenov
Telerik team
answered on 28 Dec 2011, 02:56 PM
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 >>

Tags
TreeView
Asked by
Prakash
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Prakash
Top achievements
Rank 1
Share this question
or