[c#] Value does not fall within the expected range

I am using the following code to update a listbox, this recieving a list from a Web service:

client.userKeywordsCompleted += new EventHandler<userKeywordsCompletedEventArgs>(client_userKeywordsCompleted);
client.userKeywordsAsync();

Using:

void client_userKeywordsCompleted(object sender, userKeywordsCompletedEventArgs e)
{

    string result = System.Convert.ToString(e.Result);

    for (int i = 0; i < e.Result.Count; i++)
    {

        ListBoxItem lbitem = new ListBoxItem();

        lbitem.Name = "lb_" + i;
        lbitem.Content = e.Result[i];

        lbitem.AddHandler(UIElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(ListBoxItem_DoubleClickEvent), true);

        listBox1.Items.Add(lbitem);

    }

This works fine, as I use it when the Child window loads, so the ListBox gets the list from the database, however, when a user selects one of the items in the ListBox, they have the option to edit the selected item. So once the edit is in place, there is an edit button, which updates the column in the table in the database. So then on the button click, I am again calling the aforementioned code to update the ListBox with the new credentials. However, this brings back the error -

"Value does not fall within the expected range."

Why can I not call the Web method on the button click, as all it is doing is refreshing the ListBox???

This question is related to c# silverlight web-services listbox

The answer is


I had from a totaly different reason the same notice "Value does not fall within the expected range" from the Visual studio 2008 while trying to use the: Tools -> Windows Embedded Silverlight Tools -> Update Silverlight For Windows Embedded Project.

After spending many ohurs I found out that the problem was that there wasn't a resource file and the update tool looks for the .RC file

Therefor the solution is to add to the resource folder a .RC file and than it works perfectly. I hope it will help someone out there


In case of WSS 3.0 recently I experienced same issue. It was because of column that was accessed from code was not present in the wss list.


Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to silverlight

Get current index from foreach loop Value does not fall within the expected range Could not find an implementation of the query pattern How to programmatically set the Image source How to trigger event when a variable's value is changed? Format Date/Time in XAML in Silverlight The HTTP request is unauthorized with client authentication scheme 'Ntlm' Difference between SelectedItem, SelectedValue and SelectedValuePath How do I space out the child elements of a StackPanel? How to automatically select all text on focus in WPF TextBox?

Examples related to web-services

How do I POST XML data to a webservice with Postman? How to send json data in POST request using C# org.springframework.web.client.HttpClientErrorException: 400 Bad Request How to call a REST web service API from JavaScript? The request was rejected because no multipart boundary was found in springboot Generating Request/Response XML from a WSDL How to send a POST request using volley with string body? How to send post request to the below post method using postman rest client How to pass a JSON array as a parameter in URL Postman Chrome: What is the difference between form-data, x-www-form-urlencoded and raw

Examples related to listbox

Getting value of selected item in list box as string Value does not fall within the expected range Get values from a listbox on a sheet How to create a listbox in HTML without allowing multiple selection? get value from DataTable Get the value for a listbox item by index How to clear all data in a listBox? C# Listbox Item Double Click Event C#: easiest way to populate a ListBox from a List In Python How can I declare a Dynamic Array