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 6076639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:37:51+00:00 2026-05-23T10:37:51+00:00

I have the following issue: I am creating a Windows Phone 7 application and

  • 0

I have the following issue: I am creating a Windows Phone 7 application and I am using a ListBox which is bound to an ObservableCollection people. The implementation of this you see below:

public class Person
{
    private string _id { get; set; }
    private string _name { get; set; }


    public Person(string Id, string Name, string Title)
    {
        _id = Id;
        _name = Name;
    }

    public string Id
    {

        get { return _id; }

        set
        {

            _id = value;

            FirePropertyChangedEvent("Id");

        }
    }

    public string Name
    {

        get { return _name; }

        set
        {

            _name = value;

            FirePropertyChangedEvent("Name");

        }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    private void FirePropertyChangedEvent(string propertyName)
    {

        if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName));

    }

}

The people Collection is filled with Person objects. They are created in the following function… listValues is my ListBox.

void svc_GetHierachyCompleted(object sender, HCMobileSvc.GetHierachyCompletedEventArgs e)
    {
        var data = e.Result.ToArray();
        listValues.ItemsSource = null;
        people.Clear();

        int i = 0;
        foreach(var item in data)
        {
            if (i == 0)
            {
                // Manager
                mgrField1.Text = item[1].ToString();
                mgrField2.Text = item[2].ToString();
                i++;
            }
            else
            {
                // Untergebenen hinzufügen
                people.Add(new Person(item[0].ToString(), item[1].ToString(), item[2].ToString()));
            }

        }

        // Update List
        listValues.ItemsSource = people;

    }

Now I have a DataTemplate with two textblocks bound to both properties Id and Name. When the SelectionChanged event is fired I try to rebuild the entire list (so I call the function above again) using the following code:

            string id = people[listValues.SelectedIndex].Id;
        MessageBox.Show(id);
        CreateHierachy(id);

The CreateHierachy just only queries a WebService which then goes into the method above. The problem is, as soon as I select a value in the ListBox I get the following error:

ArgumentOutOfRangeException {"\r\nParameter name: index"}

The error is caused by the line listValues.SelectedIndex.
I absolutely have no idea why that happens. What I know is that the MessageBox shows me the correct SelectedIndex value. What I also know is that when I remove the line people.Clear() that the error goes away but the ListBox does not get Updated.

Any ideas where the problem might be?

Thanks!!!

Bye,
WorldSignia

  • 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-23T10:37:51+00:00Added an answer on May 23, 2026 at 10:37 am

    You should check here for SelectedIndex being >= 0:

    if (listValues.SelectedIndex >= 0)
         string id = people[listValues.SelectedIndex].Id;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following issue, Im creating a windows 7 gadget, which uses Iframe
I have following issue: I'm introducing new feature into application (run as Windows Service)
I have the following issue using java 1.4 I try to display a very
I have the following issue: I open a dialog box with jQuery UI. This
I am using Django 1.3 and have the following issue: In the Admin list
I have an issue that on one computer applications developed using the Windows Presentation
I've asked a few questions which have touched around this issue, but I've been
I have the same issue as Creating an additional related model with Devise (which
Using Internet Explorer (don't appear to have an issue in FireFox) the following code
I have the following issue related to iterating over an associative array of strings

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.