Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
512 views
in Technique[技术] by (71.8m points)

Textbox text to listbox items vb.net

Ok so i have a textbox that gets items from a website and pastes in that then the list box adds the items but i want each line in textbox to be a new item instead it just adds it all as one

heres my code

    '  Procedure:
    Dim Str As System.IO.Stream
    Dim srRead As System.IO.StreamReader
    Try
        ' make a Web request
        Dim req As System.Net.WebRequest = System.Net.WebRequest.Create("http://76.31.248.130/videos.txt")
        Dim resp As System.Net.WebResponse = req.GetResponse
        Str = resp.GetResponseStream
        srRead = New System.IO.StreamReader(Str)
        ' read all the text 
        TextBox2.Text = srRead.ReadToEnd
    Catch ex As Exception
        TextBox2.Text = "Unable to download content"
    Finally
        '  Close Stream and StreamReader when done
        srRead.Close()
        Str.Close()
    End Try
    ' Assign string to reference.
    Dim value1 As String = TextBox2.Text


    ' Replace word with another word.
    Dim value2 As String = value1.Replace("<br>", vbNewLine)
    TextBox2.Text = value2
    ListBox1.Items.Add(TextBox2.Text)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your question is very hard to understand. I think the answer is to split the textbox's text into an array where each item is a single line and then add each of these to the listbox.

You probably want:

ListBox1.Items.AddRange(TextBox2.Text.Split(vbNewLine))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...