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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to use streamwriter with a listbox

Status
Not open for further replies.

UUVGuy

Technical User
Jun 4, 2005
57
US
I'm having a problem getting data from a listbox into the .txt file when using streamwriter. I can get data into the .txt file but it is not legible or useable.
The code I am using looks like this:
m_objOutput.WriteLine(lstSalaryTotals.Items)
I have tried various combinations after the . and even leaving as
m_objOutput.WriteLine(lstSalaryTotals) all to no avail.
Any help would be appeciated.

 
Code:
m_objOutput.WriteLine(lstSalaryTotals.Items)
This will cause ToString() to be called on the list box's Items property, which is of type ObjectCollection. Usually, the default implementation of ToString() returns the name of the class, and that's probably what you're seeing.

What you need to do is iterate through the Items collection and write each item to the Console yourself. Use the For Each..Next construct to do this.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top