0

I am trying to populate a multiline textbox with names that are selected. When I use the code below it just adds the record on the same line after the first one. Is it possible to after the first line is added to have the next item added appear on a new line?

Protected Sub Add_Click(sender As Object, e As EventArgs) Handles Button1.Click
    TextBox1.Text.Replace(Environment.NewLine, "<br />")
    TextBox1.Text += NameTextBox.Text

End Sub
4

1 回答 1

3

I don't understand the Replace you are doing, why not just writing a new line? With the .NET new line, that is, Environment.NewLine.

Protected Sub Add_Click(sender As Object, e As EventArgs) Handles Button1.Click
    TextBox1.Text &= NameTextBox.Text & Environment.NewLine
End Sub

NOTE: for string concatenation better use & rather than +.

NOTE2: if the reason for your replacement is adding <br> to use the resulting string in an external application, bear in mind that VB.NET (winforms... or code behind of ASP.NET) does not recognise <br> as new line. Use a valid character (as the aforementioned Environment.NewLine) while dealing with the controls and perform the replacement just at the end (when the VB.NET will not use it anymore).

于 2013-09-09T17:56:26.533 回答