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

Change datasource (data bound with Entity Framework 6) at runtime

1 Answer 47 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
MartinM asked on 04 Sep 2014, 07:56 PM
I noticed a change between using the RadTreeView Q2 2014 sp1 and Q1 2013 controls: 
I have some data of many-to-many Users *--* Groups. On load, I display the data Users > Groups. But on a button click I change the display to Groups > Users.
I followed the databinding procedures for hierarchical data in and, with success.
(I use EF 6, context.Users.Local.ToBindingList() for the datasource, or context.Groups.Local.ToBindingList(), for the other direction).

In the 2013 version of the control, I was able to just reassign the datasource with no problem during runtime. With the newest version of the control I get this error: 
Type: System.NullReferenceException
Target: GetProperties
Exception: Object reference not set to an instance of an object.
Stack Trace:    at Telerik.WinControls.UI.BindingProvider.GetProperties(CurrencyManager cm, String childMember, Int32 level)
   at Telerik.WinControls.UI.BindingProvider.GetObjectRelationDescriptor(RelationBinding relation, CurrencyManager cm, Int32 level)
   at Telerik.WinControls.UI.BindingProvider.RegisterObjectRelation()
   at Telerik.WinControls.UI.BindingProvider.Reset()
   at Telerik.WinControls.UI.BindingProvider.root_PropertyChanged(Object sender, PropertyChangedEventArgs e)
   at Telerik.WinControls.UI.RelationBinding.OnPropertyChanged(String propertyName)
   at Telerik.WinControls.UI.RelationBinding.set_DataSource(Object value)
   at Telerik.WinControls.UI.BindingProvider.set_DataSource(Object value)
   at Telerik.WinControls.UI.RadTreeView.set_DataSource(Object value)

I am able to get around this by setting the source to null first:
    RadTreeView1.DataSource = Nothing
    RadTreeView1.DataSource = context.Groups.Local.ToBindingList()

Is this by design or is there something I am missing here, such as a better way to achieve this behavior?


1 Answer, 1 is accepted

Sort by
Dess | Tech Support Engineer, Principal
Telerik team
answered on 09 Sep 2014, 03:03 PM
Hello Martin,

Thank you for writing.

I was able to reproduce the problem you are facing with rebinding the RadTreeView. I have logged it in our feedback portal. You can track its progress, subscribe for status changes and add your vote/comment to it on the following link - feedback item. I have also updated your Telerik points.

It seems that setting first the DataSource property to null is suitable solution for your specific case. Thus, you reset the RadTreeView before changing the ne data source.

I hope this information helps. Should you have further questions, I would be glad to help.

Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
Asked by
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question