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

RadTreeView - Binding to Custom Business Objects

8 Answers 577 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 21 Sep 2007, 12:03 AM
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

8 Answers, 1 is accepted

Sort by
0
Jordan
Telerik team
answered on 21 Sep 2007, 06:57 AM
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
0
Martin
Top achievements
Rank 1
answered on 21 Sep 2007, 03:53 PM
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:

        private void AddArtistData1() 
        { 
            BindingSource bindingSource = new BindingSource(GetArtistObjects(), ""); 
            radTreeView1.DataSource = bindingSource; 
            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"
        } 


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.

        private void AddArtistData2() 
        { 
            radTreeView1.RootRelationDisplayName = "Artists"
            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; 
        } 


Cheers
Martin


0
Jordan
Telerik team
answered on 24 Sep 2007, 12:45 PM
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
0
Amruta
Top achievements
Rank 1
answered on 23 Jan 2010, 03:02 PM
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. 
0
Victor
Telerik team
answered on 25 Jan 2010, 10:13 AM
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.
0
Shervin Nazemi
Top achievements
Rank 1
answered on 02 Mar 2010, 01:04 AM
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;

 

}

0
Victor
Telerik team
answered on 02 Mar 2010, 08:47 AM
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.
0
Stefan
Telerik team
answered on 21 Mar 2011, 10:10 AM
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
Tags
Treeview
Asked by
Martin
Top achievements
Rank 1
Answers by
Jordan
Telerik team
Martin
Top achievements
Rank 1
Amruta
Top achievements
Rank 1
Victor
Telerik team
Shervin Nazemi
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or