RadTreeView - Binding to Custom Business Objects

9 posts, 0 answers
  1. Martin
    Martin avatar
    2 posts
    Member since:
    Sep 2007

    Posted 20 Sep 2007 Link to this post

    Has anyone been able to get a RadTreeView to bind to custom business objects?
    I followed the example in the help but it only seems to show my first level artist nodes.  In fact it doesn't even show the top level 'Artists' node.

    I was also initially getting null object errors adding to the RelationBindings collection.  It seems the collection is not initialized until you call some other method like RadTreeView.DataSource.

    The example also only seems to use a single binding source and then uses compound property references to navigate the sub-relationships e.g. "Albums.Songs", whereas the DataSet example sets up a different binding source for each type of data.

    Also assuming I could get this to work, what is the liklihood that it will be two way.  I tried editing the name of a top level node and that seems to push the name back into the source data object.  But what will happen if I start dragging and dropping.  Is it to much to expect that it will handle this too?  I guess that would be problematic for the Artists/Albums/Songs example because you could drag a Song to an Artist.   However, I have a need for a generic type hierarchy where all nodes are the same type and so a node can be dragged pretty much anywhere.

    Thanks for any input
    Martin
  2. Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 21 Sep 2007 Link to this post

    Hi Martin,

    In our test RadTreeView successfully binds to the business objects used in our example.
    It will be best if you can open a support ticket and send us a simple project that demonstrates your binding issues.

    It is normal behavior for the RelationBindings collection to be null if you are binding to self referencing data
    (if you set ParentIDMember).
    The difference between the example comes from the fact that there are in business objects data relations are usually implemented as nested collections.

    RadTreeView does not currently support drag and drop when it is bound to a data source. That is because such functionality strongly depends on the data source and/or some business logic and it is very hard to provide generic support for such functionality that works in all cases.

    Thank you for your cooperation.

    Kind regards,
    Jordan
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Martin
    Martin avatar
    2 posts
    Member since:
    Sep 2007

    Posted 21 Sep 2007 Link to this post

    Hi
    I was able to get this to work eventually.  It seems like it's very dependent on the order of the code.

    The original example from the help still doesn't work for me.  It throws a NullReferenceException when adding the first RelationBinding because the RelationBindings collection has not been initialized yet.

            private void AddArtistDataTelerikExample() 
            { 
                BindingSource bindingSource = new BindingSource(GetArtistObjects(), ""); 
                RelationBinding albumsBinding = new RelationBinding("Albums", bindingSource); 
                albumsBinding.DisplayName = "Albums"
                radTreeView1.RelationBindings.Add(albumsBinding); 
                radTreeView1.RelationBindings.Add(new RelationBinding("Songs", bindingSource, "Albums.Songs")); 
                radTreeView1.RootRelationDisplayName = "Artists"
                radTreeView1.DataSource = bindingSource; 
            } 


    To fix this I tried setting the DataSource earlier (to line 4) because I saw that setting the DataSource initialized the RelationBindings collection:

    1        private void AddArtistData1() 
    2        { 
    3            BindingSource bindingSource = new BindingSource(GetArtistObjects(), ""); 
    4            radTreeView1.DataSource = bindingSource; 
    5            RelationBinding albumsBinding = new RelationBinding("Albums", bindingSource); 
    6            albumsBinding.DisplayName = "Albums"
    7            radTreeView1.RelationBindings.Add(albumsBinding); 
    8            radTreeView1.RelationBindings.Add(new RelationBinding("Songs", bindingSource, "Albums.Songs")); 
    9            radTreeView1.RootRelationDisplayName = "Artists"
    10        } 


    However, with the code ordered like this, there is no root 'Artists' node and the 'Artist' nodes don't have any children.

    I was finally able to get it to work by leaving the DataSource initialization in it's original place and moving the initialization of the root relation display name up.

    1        private void AddArtistData2() 
    2        { 
    3            radTreeView1.RootRelationDisplayName = "Artists"
    4            BindingSource bindingSource = new BindingSource(GetArtistObjects(), ""); 
    5            RelationBinding albumsBinding = new RelationBinding("Albums", bindingSource); 
    6            albumsBinding.DisplayName = "Albums"
    7            radTreeView1.RelationBindings.Add(albumsBinding); 
    8            radTreeView1.RelationBindings.Add(new RelationBinding("Songs", bindingSource, "Albums.Songs")); 
    9            radTreeView1.RootRelationDisplayName = "Artists"
    10            radTreeView1.DataSource = bindingSource; 
    11        } 


    Cheers
    Martin


  5. Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 24 Sep 2007 Link to this post

    Hello Martin,

    Glad to hear that you solved your problem.

    As you have noticed, the current implementation of data binding in RadTreeView makes some assumptions about the order in which data binding properties are set.
    We intend to change the implementation of data binding in RadTreeView so that the order the properties are set does not matter any more. You can expect these enhancements in the 2007 Q2 SP1 release.

    Thank you for your assistance.
     

    Best wishes,
    Jordan
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. Amruta
    Amruta avatar
    18 posts
    Member since:
    Apr 2009

    Posted 23 Jan 2010 Link to this post

    Hi,

    I have created a rad tree view programmatically.
    I create tree view item for each item in a list. Now i want to bind each node (or tree view item ) to a business object so that when i click on the node i can retrieve the whole object associated with that node and call a function by passing that object. How can i achieve it? I have not used binding source but i am creating the tree view at runtime.

    Thanks
    Amruta. 
  7. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 25 Jan 2010 Link to this post

    Hello Amruta,

    Thank you for your question. Please use the Tag property of RadTreeNode in order to associated it with a data object while creating the node. Then it is simply a matter of reading the Tag property. Please write again if you need further assistance.

    Regards,
    Victor
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  8. Shervin Nazemi
    Shervin Nazemi avatar
    1 posts
    Member since:
    Mar 2010

    Posted 01 Mar 2010 Link to this post

    Hi
    Our treeview does not show the notes from our database.
    Below is example of our code;

    rtvCommissionReport.DataSource = ctx.CommissionProcessLogs.GetNewBindingList();

     

    rtvCommissionReport.RootRelationDisplayName =

    "Commission Report";

     

    rtvCommissionReport.DisplayMember =

    "Name";

     

    rtvCommissionReport.ValueMember =

    "Id";

     

     

    //At this point I can see the rtvCommissionReport has all the necessary information in the object. However the count is zero and the actual treeview does not show any result.

     

     

    if (rtvCommissionReport.Nodes.Count > 0)

     

    {

    rtvCommissionReport.Nodes[0].Expanded =

    true;

     

    rtvCommissionReport.Nodes[0].Selected =

    true;

     

    }

  9. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 02 Mar 2010 Link to this post

    Hi Shervin Nazemi,

    Thank you for writing. The code you provided should be working as expected, so far there have been no reports of RadTreeView failing to bind quietly. Please provide more details on your scenario and the version of the controls that you are using. I am looking forward to your reply.

    Best wishes,
    Victor
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  10. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 21 Mar 2011 Link to this post

    Hello Shervin,

    I am glad to inform you that in Q1 2011 we have introduced a major upgrade of RadTreeView control, which is now virtualized and fully customizable. Feel free to download the latest release and try it out. For more information on our latest release refer to this blog post.

     
    Kind regards,
    Stefan
    the Telerik team
Back to Top
UI for WinForms is Visual Studio 2017 Ready