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

    Hello,
    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

    Pete.

    Animals
      -- Mammals
           Cats
           Dogs
           Rabbits
      -- Reptiles
           -- With Legs
         Crocodile
                Lizard
           -- Without Legs
                -- Snakes
                     Cobra
                     Rattlesnake
         Legless Lizard
      -- Fish
           -- Fresh Water
                Roach
                Bream       
           -- Salt Water
                Edible
                   -- Flat
          Skate
                        Soul
            Cod
                   Salmon
      -- Insects
           -- Flying
                Bees
                Wasps
           -- Crawling
         Beetles
                Ants         

  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>
      <
    telerik:RadTreeViewItem Header="Vegetable" />
      <telerik:RadTreeViewItem Header="Mineral" />
    </telerik:RadTreeView>

    I can create the 3 Root nodes using
    myTreeView.AddItemByPath("Animal");
    myTreeView.AddItemByPath("Vegetable");
    myTreeView.AddItemByPath("Mineral");
    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.
    Regards,
    Pete Davies.

  3. Answer
    Valentin.Stoychev
    Admin
    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> 
                <telerik:RadTreeViewItem Header="Fish">  
                    <telerik:RadTreeViewItem Header="Fresh Water">  
                        <telerik:RadTreeViewItem Header="Roach"/>  
                        <telerik:RadTreeViewItem Header="Bream"/>  
                    </telerik:RadTreeViewItem> 
                    <telerik:RadTreeViewItem Header="Salt Water">  
                        <telerik:RadTreeViewItem Header="Edible"/>  
                        <telerik:RadTreeViewItem Header="Flat">  
                            <telerik:RadTreeViewItem Header="Skate"/>  
                            <telerik:RadTreeViewItem Header="Soul"/>  
                        </telerik:RadTreeViewItem> 
                    </telerik:RadTreeViewItem> 
                </telerik:RadTreeViewItem> 
            </telerik:RadTreeView> 


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

    I'm attaching an example project for your reference.

    Please let us know if you need any help.

    Kind regards,
    Valentin.Stoychev
    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,

    Pete.

Back to Top