[Help]Add Listbox Items per line[Solved]

Posts 1–13 of 13 · Page 1 of 1
[Help]Add Listbox Items per line[Solved]
This is sudden guys but I need the code for adding listbox items per line at textboxes or a text file.

It will be for the log
Wait, do you mean add each line from a textfile as new listbox entry, or write each listbox entry to a textfile?
Code:
dim content As String = ""
foreach item As string In listbox.Items
textbox.Items.Add(item)
content += item
next
if File.Exists("out.txt")
then
File.Delete("out.txt")
end if
File.WriteAllText("out.txt")
her is code. typed on mobile, first ever time i tried doing this :L
Quote Originally Posted by freedompeace View Post
Code:
dim content As String = ""
foreach item As string In listbox.Items
textbox.Items.Add(item)
content += item
next
if File.Exists("out.txt")
then
File.Delete("out.txt")
end if
File.WriteAllText("out.txt")
her is code. typed on mobile, first ever time i tried doing this :L
Don't need to delete the file, WriteAllText doesn't append text. I would just say:

Code:
IO.File.WriteAllLines("C:\VB Projects\out.txt", ListBox1.Items.Cast(Of String).ToArray)


And leave it at that
Quote Originally Posted by Jason View Post


Don't need to delete the file, WriteAllText doesn't append text. I would just say:

Code:
IO.File.WriteAllLines("C:\VB Projects\out.txt", ListBox1.Items.Cast(Of String).ToArray)


And leave it at that
=) Nice ... Im gonna use this xD

PS: What change is coming?
Let's say in the textbox the content is
Code:
Content 1
Content 2
Content 3
then every line of it will appear in each item.
Quote Originally Posted by nathanael890 View Post
Let's say in the textbox the content is
Code:
Content 1
Content 2
Content 3
then every line of it will appear in each item.
Code:
ListBox1.Items.AddRange(TextBox1.Lines)
Is that what you're after?
Quote Originally Posted by nathanael890 View Post
Let's say in the textbox the content is
Code:
Content 1
Content 2
Content 3
then every line of it will appear in each item.
Edit: Jason answered it. Is that what ya want ?
Actually He did it in reverse..
but I don't need it as I already know it.

I was looking for adding some items on every line on a textbox or a text file..

I think it includes the "Enter" button..
Quote Originally Posted by nathanael890 View Post
Actually He did it in reverse..
but I don't need it as I already know it.

I was looking for adding some items on every line on a textbox or a text file..

I think it includes the "Enter" button..
Set Multiline property of Textbox to True via properties.

Or by code:

Code:
Textbox1.Multiline = True
This way you can use the Enter button !

...?
Quote Originally Posted by nathanael890 View Post
Actually He did it in reverse..
but I don't need it as I already know it.

I was looking for adding some items on every line on a textbox or a text file..

I think it includes the "Enter" button..
Sorry, I don't understand what you want, you keep changing your mind. Please give a decent explanation
Quote Originally Posted by Jason View Post


Sorry, I don't understand what you want, you keep changing your mind. Please give a decent explanation
I wasn't talking about you... It was from the other guy and I did a wrong grammar.. anyway,

the code works as you said... thanks for it..
I do also use this code that I found but more than codes than yours..
Code:
For Each Line As String In TextBox1.Lines
ListBox1.Items.Add(Line)
Next
Thanks..
Alright, marked as solved. No posting unless it's relevant and the thread is under a week old.

As for the code differences, addrange does pretty much the same thing as looping through the elements and adding them all, albeit tidier.
Posts 1–13 of 13 · Page 1 of 1
This thread is closed for replies.

Tags for this Thread

None

Talk with us