How to handle empty ItemsSource collection

4 posts, 0 answers
  1. Martin
    Martin avatar
    26 posts
    Member since:
    Jul 2012

    Posted 16 Oct 2012 Link to this post

    I use RadListPicker in my app. It's used for selecting target location, user can define all locations in the list, but it could empty as well.

    The problem is how to handle the situation when the list of locations is empty? Currently is shows empty box and when I click it, it gets highlighted and won't return back to unhighlighted state (i guess it waits for selection, but none can happen if there is no item in the list).

    I'd like to show a message "location list is empty" when there is no location to show and also to prohibit the editing (this could be achieved using converter for the Enabled property I guess)

    I tried using ItemTemplate for returning that empty message or even SummaryForSelectedItemsDelegate, but when there is no item in source list, it's never called.

     <telerikInput:RadListPicker Header="header" ItemsSource="{Binding Locations}" SelectedItem="{Binding EditedLocation, Mode=TwoWay}" />

  2. Deyan
    Admin
    Deyan avatar
    2039 posts

    Posted 18 Oct 2012 Link to this post

    Hello Martin,

    Thanks for writing.

    RadListPicker is designed with the intention to allow the users to pick from a predefined set of values. Its concept implies that it should always have a source and selection unless the Multiselect  mode is activated.

    In your scenario I can suggest you implement a mechanism that hides the List Picker when no location can be selected and displays a corresponding message or similar.

    I hope this helps.

    Kind regards,
    Deyan
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. Martin
    Martin avatar
    26 posts
    Member since:
    Jul 2012

    Posted 18 Oct 2012 Link to this post

    Yes, that's what I though as a last resort behavior.

    Anyway adding mechanism for showing "Empty list message" would be a great feature. There is already similar feature in DataBoundListBox.

  5. Deyan
    Admin
    Deyan avatar
    2039 posts

    Posted 18 Oct 2012 Link to this post

    Hello Martin,

    Thanks for writing back.

    There is already a mechanism for displaying empty content message: the NoSelectionContent property. This property, however, works only when the selection mode is set to be Multiselection. When the selection mode is set to be single we assume that there will always be a selected item from the source.

    Greetings,
    Deyan
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top