Listbox question

  • Thread starter Thread starter HardySpicer
  • Start date Start date
H

HardySpicer

I have a listbox and I need to store the entire contents to a text
file.(ie I don't need to select them with a mouse - just store the
lot!)

Dim oWrite As System.IO.StreamWriter
oWrite = IO.File.CreateText("C:\store_search.txt")

oWrite.WriteLine(Listfullpath1.SelectedItems.ToString)
oWrite.Close()
Doesn't work of course. I think I need to select the items one by one
by incrementing a counter.

any ideas?

H.
 
I have a listbox and I need to store the entire contents to a text
file.(ie I don't need to select them with a mouse - just store the
lot!)

Dim oWrite As System.IO.StreamWriter
            oWrite = IO.File.CreateText("C:\store_search.txt")

            oWrite.WriteLine(Listfullpath1.SelectedItems.ToString)
            oWrite.Close()
Doesn't work of course. I think I need to select the items one by one
by incrementing a counter.

any ideas?

H.

That should do the trick:

'----------------------------------
Using writer As New System.IO.StreamWriter _
("C:\store_search.txt")

' Loop through listbox to save each item
For x As Integer = 0 To ListBox1.Items.Count - 1
writer.WriteLine(ListBox1.Items.Item(x))
Next

End Using
'----------------------------------

Hope this helps,

Onur Güzel
(e-mail address removed)
(e-mail address removed)
 
That should do the trick:

'----------------------------------
Using writer As New System.IO.StreamWriter _
("C:\store_search.txt")

' Loop through listbox to save each item
For x As Integer = 0 To ListBox1.Items.Count - 1
writer.WriteLine(ListBox1.Items.Item(x))
Next

End Using
'----------------------------------

Hope this helps,

Onur Güzel
(e-mail address removed)
(e-mail address removed)

Fantastic - works great. Thanks

H
 
Back
Top