2011-08-16 124 views
-3

好吧,所以我有一個文本框,從網站獲取項目和粘貼,然後列表框添加項目,但我希望在文本框中的每一行是一個新的項目,而不是它只是增加這一切作爲一個文本框文本到列表框項目vb.net

繼承人我的代碼

' 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) 

回答

2

你的問題很難理解。我認爲答案是將文本框的文本分成一個數組,其中每個項目是一行,然後將其中的每一個添加到列表框中。

你可能想:

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

它的那樣簡單 ListBox1.Items.AddRange(TextBox1.Text.Split(vbNewLine))或 ListBox1.Items.AddRange(TextBox1.Text.Split(vbcrlf )

1

嘗試使用srRead.readline代替srRead.readtoend

Dim a As String 
Try 
     Do 
      a = srRead.ReadLine 
      If a <> Nothing Then 
       ListBox1.Items.Add(a) 
      End If 
     Loop Until a Is Nothing 
    Catch 
    End Try 

很抱歉,如果我沒有理解你的問題