Getting "SelectedItem is not contained within the ItemsSource"

3 posts, 0 answers
  1. catqbat
    catqbat avatar
    9 posts
    Member since:
    Jun 2013

    Posted 01 Jul 2014 Link to this post

    Hello,

    I'm experiencing strange issue with RadListPicker.

    This is how the xaml part looks like:

    <telerikInput:RadListPicker 
    ItemsSource="{Binding AvailableUsers}" SelectedItem="{Binding SelectedUser, Mode=TwoWay}"
    DisplayMemberPath="Login"  
    NoSelectionContent="Select user..."
     />

    The control is bound to ViewModel, which contains two properties: observable collection "AvailableUsers", and "SelectedUser" of proper type. 
    On every page load collection is being populated with data which comes from web service.

    At the initial page load everything works fine, but when I navigate away and then come back, I'm getting "SelectedItem is not contained within the ItemsSource" error.

    This is how the code looks like:

    AvailableUsers = null;
    SelectedUser = null;

    AvailableUsers = e.Result; //<-- this throws Exception

    e.Result is data from web service containing collection of users. The last line throws Exception and when the debugger stops in this point I can see that SelectedUser is not null (take a look at my attached screenshot).
    So when this happens app continues to run, but list picker displays "Select user..." string - as if there was no selection. When I select an item, viewmodel is being notifed but control still displays "Select user..." you can't see the change.


    The issue is quite tricky, I tried to make simplified test solution with similar scenario, but was unable to get the error.


    Any ideas?


  2. Rosy Topchiyska
    Admin
    Rosy Topchiyska avatar
    551 posts

    Posted 04 Jul 2014 Link to this post

    Hello Agata,

    Thank you for contacting us.

    From the provided information it is not completely clear what is your scenario, but we succeeded to reproduce such error when using a static view model. Could you please try to replace this code:
    AvailableUsers = null;
    SelectedUser = null;
    AvailableUsers = e.Result;
    With:
    this.AvailableUsers.Clear();
    foreach (var user in e.Result)
    {
        this.AvailableUsers.Add(user);
    }
    And let us know if this works fine. If not, we will need some more information about your scenario: could you please send us a sample project that replicates the navigation logic and the view model bindings from your app.

    I look forward to your reply.

    Regards,
    Rosy Topchiyska
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. DevCraft banner
  4. catqbat
    catqbat avatar
    9 posts
    Member since:
    Jun 2013

    Posted 05 Jul 2014 in reply to Rosy Topchiyska Link to this post

    Yes, this approach does solve the issue :)

    Thank you!
Back to Top