This is a migrated thread and some comments may be shown as answers.

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

7 Answers 162 Views
ListPicker
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Gary Davis
Top achievements
Rank 2
Gary Davis asked on 15 May 2011, 12:47 AM
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

7 Answers, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 19 May 2011, 08:57 AM
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>>
0
Rohan
Top achievements
Rank 1
answered on 02 Feb 2013, 10:51 PM
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.
0
Victor
Telerik team
answered on 07 Feb 2013, 08:32 AM
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.
0
Rohan
Top achievements
Rank 1
answered on 19 Feb 2013, 05:20 AM
Not sure how to use Dispatcher.Invoke(). Can you please reply with a code sample?

And FIVE DAYS to respond to a query?
0
Kiril Stanoev
Telerik team
answered on 21 Feb 2013, 12:46 PM
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.
0
Peter
Top achievements
Rank 1
answered on 10 Aug 2013, 02:36 AM
Why does it select the first item when the datasource is set (or even the collection is changed)? This is really strange
0
Kiril Stanoev
Telerik team
answered on 12 Aug 2013, 11:41 AM
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 >>
Tags
ListPicker
Asked by
Gary Davis
Top achievements
Rank 2
Answers by
Victor
Telerik team
Rohan
Top achievements
Rank 1
Kiril Stanoev
Telerik team
Peter
Top achievements
Rank 1
Share this question
or