How to create irregular tree

4 posts, 1 answers
  1. Meerkat
    Meerkat avatar
    64 posts
    Member since:
    Feb 2007

    Posted 11 Aug 2008 Link to this post

    Firstly, I need to say that I am far from being a proogramming guru so please do not make any assumptions about my ability.

    I am considering using your treeview on my site.
    I have spent the day trying to work out what it can and cannot do.

    As far as I can see, most, if not all, your examples use a fixed number of levels (or branches, or whatever you prefer to call them). All the branches are the same. For example, each artist has a number of albums, and each album has a number of songs.

    At the end, is my attempt to show an example of a tree that has an irregular structure.

    My question is "How would you suggest go about creating such a tree".
    Database, XML file or perhaps dynamically produce some XAML?

    The data will be given to me via a spreadsheet, but that is not really important.
    I am hoping to work out how to import the spreadsheet into the tree once you point me in the right direction.

    Best Regards


      -- Mammals
      -- Reptiles
           -- With Legs
           -- Without Legs
                -- Snakes
         Legless Lizard
      -- Fish
           -- Fresh Water
           -- Salt Water
                   -- Flat
      -- Insects
           -- Flying
           -- Crawling

  2. Meerkat
    Meerkat avatar
    64 posts
    Member since:
    Feb 2007

    Posted 12 Aug 2008 Link to this post

    I wanted to add some stuff to the end of my post but, strangely, it said something about you not replying to edited posts. Hopefully the logic of things like this will become more clear to me as I move from debutant to beginner on the ladder of experience.

    I am not sure how long it takes to get a reply so please forgive me if I have not waited long enough. Would I have been better off using a Support Ticket. I thought it might be more beneficial to others to ask questons on this forum.

    If my original question is too hard, or too obvious or just too difficult to understand ( believe me, I am aware of my poor communications skills ), perhaps I could ask start by asking something more basic.

    How can I create the following in code behind?

    <telerik:RadTreeView x:Name="myTreeView" Height="300" Width="300">
      <telerik:RadTreeViewItem Header="Animal" >
        <telerik:RadTreeViewItem Header="Dog" />
        <telerik:RadTreeViewItem Header="Cat" />
    telerik:RadTreeViewItem Header="Vegetable" />
      <telerik:RadTreeViewItem Header="Mineral" />

    I can create the 3 Root nodes using
    but cannot work out how to two Animal leaves ( Dog and Cat )

    Obviously I would like to databind to some source instead of dynamically creating the tree. Sadly, there does not seem to be any documention anywhere that tells me how I might do this. Hopefully you will be able to find time to get back to me sometime. I understand how busy you must be, so I will try to be patient. Would you suggest I use Support Tickets in future?

    Hopfully, I have not cancelled my request by replying to my own thread.
    Pete Davies.

  3. Answer
    Valentin.Stoychev avatar
    2198 posts

    Posted 12 Aug 2008 Link to this post

    Hi Pete,

    First of all - thank you for your interest in our Silverlight controls.

    You have several options to implement this scenario. There is no limitation in the level of nesting.

    You can declare it in the XAML by staticaly adding the collection of animalas you have:
            <telerik:RadTreeView x:Name="myTreeView" Height="300" Width="300">  
                <telerik:RadTreeViewItem Header="Animal" > 
                    <telerik:RadTreeViewItem Header="Dog" /> 
                    <telerik:RadTreeViewItem Header="Cat" /> 
                <telerik:RadTreeViewItem Header="Fish">  
                    <telerik:RadTreeViewItem Header="Fresh Water">  
                        <telerik:RadTreeViewItem Header="Roach"/>  
                        <telerik:RadTreeViewItem Header="Bream"/>  
                    <telerik:RadTreeViewItem Header="Salt Water">  
                        <telerik:RadTreeViewItem Header="Edible"/>  
                        <telerik:RadTreeViewItem Header="Flat">  
                            <telerik:RadTreeViewItem Header="Skate"/>  
                            <telerik:RadTreeViewItem Header="Soul"/>  

    Your second option will be to create XML and to bind the treeview to that XML. Here is the XML I've prepared:
      <XmlNodeItem Header="Animal">  
          <XmlNodeItem Header="Dog" /> 
          <XmlNodeItem Header="Cat" /> 
      <XmlNodeItem Header="Fish">  
          <XmlNodeItem Header="Fresh Water">  
              <XmlNodeItem Header="Roach"/>  
              <XmlNodeItem Header="Bream"/>  
          <XmlNodeItem Header="Salt Water">  
              <XmlNodeItem Header="Edible"/>  
              <XmlNodeItem Header="Flat">  
                  <XmlNodeItem Header="Skate"/>  
                  <XmlNodeItem Header="Soul"/>  

    I'm attaching an example project for your reference.

    Please let us know if you need any help.

    Kind regards,
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  4. Meerkat
    Meerkat avatar
    64 posts
    Member since:
    Feb 2007

    Posted 12 Aug 2008 Link to this post

    Crikey Valentin !

    Your reply was beyond all my expectations.

    I am really impressed with the trouble you have gone to help.

    What you have done is perfect. I now understand a lot better how the tree works.
    If it were possible for me to give you a 1000 Telerik points, I would do so right now :-)

    I am very happy,
    Best regards,


Back to Top