Setting RadListPicker ItemsSource causes SelectionChanged to fire with index set to 0

8 posts, 0 answers
  1. Gary Davis
    Gary Davis avatar
    71 posts
    Member since:
    Oct 2003

    Posted 14 May 2011 Link to this post

    I am setting a list of two items to the RadListPicker ItemsSource (set in the Loaded event):

       RadAreaCodePicker.ItemsSource = areaCodes.Select(s => s.AreaCode);


    Debugging shows the SelectionChanged event firing with the index set to 0 (first item in the list). This causes the item to be processed which I don't want to do.

    The next statement I set the selected item to the one I want as the default. If it it other than item 0, the SelectionChanged fires again.

       RadAreaCodePicker.SelectedItem = areaCode;


    Xaml:

     

    <telerikInput:RadListPicker Height="72" HorizontalAlignment="Right" Margin="0,35,322,0" Name="RadAreaCodePicker" VerticalAlignment="Top" Width="65" FontWeight="Bold" FontSize="30" SelectionChanged="RadAreaCodePicker_SelectionChanged" />

     


    Thanks,
    Gary Davis

  2. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 19 May 2011 Link to this post

    Hi Gary Davis,

     Thank you for writing.

    You can easily skip the processing of the event by unsubscribing from selection changed, setting the new items source, setting the correct selected item and then resubscribing to the event. RadListPicker selects the first item when a new data source is set and this behavior is by design, RadListPicker does not support null selection.

    Please write again if you need further assistance.

    Kind regards,
    Victor
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  3. DevCraft banner
  4. Rohan
    Rohan avatar
    3 posts
    Member since:
    Aug 2012

    Posted 02 Feb 2013 Link to this post

    Hi Victor, how would I go about unsubscribing from the event? I have this in my code, but it doesn't seem to be working:

    radListPicker.SelectionChanged -= radListPicker_SelectionChanged;
    radListPicker.ItemsSource = possibleValuesString;
    radListPicker.SelectedIndex = 4;
    radListPicker.SelectionChanged += radListPicker_SelectionChanged;

    private void radListPicker_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        Prompt.Visibility = Visibility.Visible;
    }

    I only want the Prompt to be visible once I select an item. Special note: I have the listpicker in a PanoramaItem and always launch it with isExpanded=true. I want the user to select an option, after which the prompt should appear.
  5. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 07 Feb 2013 Link to this post

    Hello Gary,

    Please explain what you mean by "it doesn't seem to be working". Is your selection changed handler called immediately after resubscribing? If so, you can delay the event subscription by using Dispatcher.BeginInvoke().
    You have to subscribe to the selection changed event inside the BeginInvoke callback.

    Kind regards,
    Victor
    the Telerik team
    Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
  6. Rohan
    Rohan avatar
    3 posts
    Member since:
    Aug 2012

    Posted 18 Feb 2013 Link to this post

    Not sure how to use Dispatcher.Invoke(). Can you please reply with a code sample?

    And FIVE DAYS to respond to a query?
  7. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 21 Feb 2013 Link to this post

    Hello Rohan,

    Thank you for contacting us. I've responded to your other thread where I've attached a sample. I'll add it to this thread as well for reference. 

    Please refer to this MSDN article on how to use Dispatcher: http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher(v=vs.95).aspx

    Dispatcher.BeginInvoke: http://msdn.microsoft.com/en-us/library/cc190259(v=vs.95).aspx

    Don't hesitate to contact us if you have further questions or comments.

    Greetings,
    Kiril Stanoev
    the Telerik team
    Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
  8. Peter
    Peter avatar
    7 posts
    Member since:
    May 2011

    Posted 09 Aug 2013 Link to this post

    Why does it select the first item when the datasource is set (or even the collection is changed)? This is really strange
  9. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 12 Aug 2013 Link to this post

    Hello Peter,

     I've posted an answer here: http://www.telerik.com/community/forums/windows-phone-8/listpicker/bind-selecteditem-to-null.aspx. Let us know what you think.

    Regards,
    Kiril Stanoev
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINDOWS PHONE 7.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top
DevCraft banner