Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to correct parameter name item cannot be null

Status
Not open for further replies.

MeonR

Programmer
Aug 16, 2002
97
US
Hello All:
I have a streamreader that reads a list of text files store
and puts them in a listbox, doing this thows a "Cannot be null value, parameter name item" exception. There seems to be no way to pass ReadLine to anything but a string what I need is an array, however this does'nt seem to work either
any ideas?
try
{
StreamReader sr = new StreamReader(cboContainer.Text); do
{
strFileName = sr.ReadLine(); this.lstFiles.Items.Add(strFileName);

} while(strFileName != "");

sr.Close();
}
catch(Exception ex)
{
MessageBox.Show("Error Loading " + ex.Message);
}

TIA
MeonR


"The beatings will continue until morale improves
 
MeonR,

I think your problem is the structure of your loop.

Here's what you coded:
do
{
try to read something
use what was read
}
while (I actually read something)

The ReadLine call will eventually return null which you then try to add to the listbox. That's the error.

You need to change your code to:
try to read something
while (I actually read something)
{
use what was read
try to read something
}

Good luck,
Andrew
 
Hello Andrew:

Tried it and no joy, repeats the same exception no matter what
any ideas?

Thanks
MeonR

"The beatings will continue until morale improves
 
Hello Andrew:

Pardon me for exceeding the bounds of common stupidity!

while((strFileName = sr.ReadLine()!=null))
{
//load listbox
}

Thanks
MeonR

"The beatings will continue until morale improves
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top