Selecting value from Radlistpicker

6 posts, 0 answers
  1. RM
    RM avatar
    4 posts
    Member since:
    May 2007

    Posted 30 Aug 2012 Link to this post

    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.

  2. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 31 Aug 2012 Link to this post

    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.

  3. DevCraft banner
  4. Randall
    Randall avatar
    5 posts
    Member since:
    Nov 2012

    Posted 28 Aug 2013 Link to this post

    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();

    ???
  5. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 29 Aug 2013 Link to this post

    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 >>
  6. Randall
    Randall avatar
    5 posts
    Member since:
    Nov 2012

    Posted 30 Aug 2013 Link to this post

    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.

  7. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 30 Aug 2013 Link to this post

    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 >>
Back to Top
DevCraft banner