Getting "SelectedItem is not contained within the ItemsSource"

Thread is closed for posting
3 posts, 0 answers
  1. catqbat
    catqbat avatar
    9 posts
    Member since:
    Jun 2013

    Posted 01 Jul 2014 Link to this post


    I'm experiencing strange issue with RadListPicker.

    This is how the xaml part looks like:

    ItemsSource="{Binding AvailableUsers}" SelectedItem="{Binding SelectedUser, Mode=TwoWay}"
    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
    Rosy Topchiyska avatar
    586 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;
    foreach (var user in e.Result)
    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.

    Rosy Topchiyska

    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. 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