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

[Solved] Selecting value from Radlistpicker

5 Answers 173 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.
RM
Top achievements
Rank 1
RM asked on 30 Aug 2012, 05:13 PM

I am having a little problem trying to get the selected value from the RadListPicker control.

How do I get the value from a select dropdown item, that is get the Content value “One”, “Two” etc…?

<telerik:RadListPicker  Height="49" Margin="0,5,5,0" InlineModeThreshold="6" SelectedIndex="0" Width="292" HorizontalAlignment="Left" Background="#BF15BED4" Name="rlpBottleSize">

                    <telerik:RadListPickerItem Content="One" Background="#BF15BED4" ></telerik:RadListPickerItem>

                    <telerik:RadListPickerItem  Content="two" Background="#BF15BED4</telerik:RadListPickerItem>

                    <telerik:RadListPickerItem Content="three" Background="#BF15BED4"></telerik:RadListPickerItem>

                </telerik:RadListPicker>

 

I was thinking that in the C# code you could do something like this:
string s = this.rlpBottleSize.SelectedVisualItem.ToString();

Or

string s = ((ListBoxItem)this.rlpBottleSize.SelectedItem).Content.ToString();

 

But these do not work to get the value.

5 Answers, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 31 Aug 2012, 09:35 AM
Hi Richard,

Thanks for writing.
You need to get the content of the visual item. For example:

this.rlpBottleSize.SelectedVisualItem.Content.ToString();
Write again if you need further assistance.

All the best,
Victor
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Randall
Top achievements
Rank 1
answered on 29 Aug 2013, 03:54 AM
I just tried the above.  Rather than the Content value, I get: "System.Windows.Controls.ListBoxItem".

My specific code is this.StateList.SelectedVisualItem.Content.ToString();

???
0
Kiril Stanoev
Telerik team
answered on 29 Aug 2013, 08:04 AM
Hi Randall,

Please try the following:

private void ListPicker_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    var item = (this.StateList.SelectedItem as RadListPickerItem).Content.ToString();
}

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 >>
0
Randall
Top achievements
Rank 1
answered on 30 Aug 2013, 05:08 AM
That didn't work either.  Generates error: "An exception of type 'System.NullReferenceException' occurred in Here I Am.DLL but was not handled in user code".

I don't understand why this.StateList.SelectedVisualItem.Content.ToString(); by itself doesn't work. 

(StateList.SelectedIndex); produces the selected index value exactly as I would expect... so why does StateList.SelectedVisualItem.Content produce the name of the control instead of the content's value?  Looks like a bug to me.

0
Kiril Stanoev
Telerik team
answered on 30 Aug 2013, 10:01 AM
Hi Randall,

Thank you for the follow-up. Please make sure you're using the latest release of RadControls for Windows Phone. Then take a look at the attached project and let me know if you're still able to reproduce the issue.

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
RM
Top achievements
Rank 1
Answers by
Victor
Telerik team
Randall
Top achievements
Rank 1
Kiril Stanoev
Telerik team
Share this question
or