Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7628331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:34:50+00:00 2026-05-31T05:34:50+00:00

I am having an issue with my ListPicker control. I have implemented my listpicker

  • 0

I am having an issue with my ListPicker control. I have implemented my listpicker in my page as follows but I am receiving an IndexOutOfRangeException upon runtime, and I am not quite sure of how to fix the problem:

SettingsPage.xaml

<phone:PhoneApplicationPage.Resources>
    <DataTemplate x:Name="SearchProviderItemTemplate">
        <TextBlock Text="{Binding SearchProvider}" />
    </DataTemplate>
</phone:PhoneApplicationPage.Resources>

<ScrollViewer x:Name="ContentPanel_Browser" Margin="12,0,12,0">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="70"/>
                        <RowDefinition Height="70"/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>

                    ...

                    <!-- Search Provider -->
                    <TextBlock Text="Search provider" Margin="12,7,12,8"
                       Grid.Row="3" VerticalAlignment="Bottom"
                       Foreground="{StaticResource PhoneSubtleBrush}"/>
                    <toolkit:ListPicker x:Name="SearchProviderListPicker" Grid.Row="4" Grid.ColumnSpan="2" Margin="12,0,12,0"  
                                        ItemTemplate="{Binding SearchProviderItemTemplate}" 
                                        SelectionChanged="SearchProviderListPicker_SelectionChanged" />
                </Grid>
            </ScrollViewer>                

SettingsPage.xaml.cs

    string searchProvider;

    String[] SearchProvider = 
    {
        "Google", 
        "Bing",
        "Yahoo",
        "Ask",
        "AOL"
    };

    private void SearchProviderListPicker_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        string selectedItem = e.AddedItems[0] as string;  //IndexOutOfRangeException was unhandled

        switch (selectedItem)
        {
            case "Google":
                searchProvider = "http://www.google.com/search?q=";
                break;
            case "Bing":
                searchProvider = "http://www.bing.com/search?q=";
                break;
            case "Yahoo":
                searchProvider = "http://search.yahoo.com/search?p=";
                break;
            case "Ask":
                searchProvider = "http://www.ask.com/web?q=";
                break;
            case "AOL":
                searchProvider = "http://search.aol.com/search?q=";
                break;
            //default:
            //    SearchProvider = "http://search.aol.com/search?q=";
            //    break;
        }

The IndexOutOfRangeException occurs with line ‘string selectedItem = e.AddedItems[0] as string;’ in SettingsPage.xaml.cs. I remember seeing how to solve this somewhere on StackOverflow but I cannot find that source now. Any idea on how to set the bounds or check to ensure this exception will not occur? Thanks in advance (any code assistance would help I am new to this!).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:34:51+00:00Added an answer on May 31, 2026 at 5:34 am

    As AddedItems is an IList, can you not just make a check that it has some items in it before you try and access them?

    Something like the following at the top of the method should solve the problem:

    if (e.AddedItems.Count <= 0)
    {
        return;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having an issue here that I have tried everything I can think of but
I have a primefaces dataList within a primefaces dataGrid but I'm having issue mapping
Having an issue with traversing in jQuery.. hopfully an easy one..but I'm banging my
I am having an issue with two-way binding the SelectedItem of the ListPicker In
Experts, I'm having issue when sending emails out. Currently, I have a feedback form
I'm following Railscasts Episode #165 Edit Multiple but having issue where when I go
We have a device that support SAE J1939 interface and having issue with finding
i'm trying to create an application using three20 but i'm having issue to set
Having some issue with my function call please. I have a situation that I
Having an issue with one my scripts. The animation keeps queueing up. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.