Hi,
It sounds like you are trying to add a value that has not been assigned yet. As you are running in a loop, make sure you are getting the value you think you are.
If you are using a for loop to read the strings, make sure the instance value you are reading contains what you expect. Example:
for (int i = 0; i <= 5; i++)
{
listboxname.items.add(sourchelist[i]);
}
Make sure that your range is correct... in other words, make sure that if you are creating a 0-base indexed list you start reading from 0, and that you stop reading at the correct point. e.g. make sure your range selector (<= 5 in the above example) is correct. Otherwise you may be trying to read from index 5 when the source list only has 5 entries (in which case you should stop reading at 4).
Make sure you assign the initial value of the string you are adding. i.e. Where you create the variable that contains the text you are adding to the list use:
string textToAdd = "";
in stead of
string textToAdd;
Which makes sure that the initial value is set.
You mentioned in your comment that you are using multi-threading. This adds a few more things to check:
1. Make sure you are not running into a race condition (Reading the value before it is set)
2. Make sure you are updating the listbox values from the same thread as the one on which the listbox is running. I usually create a utility method in that code that you can call from other threads to update the listbox:
private void AddToListBox(string str)
{
if (InvokeRequired) BeginInvoke(new Action<string>(AddToListBox), str);
else listboxname.Items.Add(str);
}
3. Make sure that if you are using queued locking to ensure your threaded data integrity, that your locks are not timing out and discarding your updates.
Hope that helps!