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

2 posts, 0 answers
  1. MartinM
    MartinM avatar
    3 posts
    Member since:
    Dec 2009

    Posted 04 Sep 2014 Link to this post

    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?


  2. Dess | Tech Support Engineer, Sr.
    Dess | Tech Support Engineer, Sr.  avatar
    3625 posts

    Posted 09 Sep 2014 Link to this post

    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.
Back to Top