0

单击复选框时,我正在向文本框中添加一行。当未单击复选框并想要删除该项目时我应该怎么做:

Private Sub cbAddress_SelectedValueChanged(sender As Object, e As System.EventArgs) Handles cbAddress.SelectedValueChanged
if cbAddress.checked = true then
    dim thetext as string = txtTextbox.text
    dim theItem as string = "test"
    txtTextbox.text = thetext & Environment.NewLine & theItem
else
    ' i'm try to delete the line.
   ' I've tried to txtTextbox.text.Remove(blah, blah)
end if 

我应该跟踪它在文本框中添加到哪一行以在未选中时将其删除,还是有更好的方法?

4

2 回答 2

0

您可以只使用String.Replace方法:

Private Sub cbAddress_SelectedValueChanged(sender As Object, e As System.EventArgs) Handles cbAddress.CheckedChanged
    Dim theItem As String = "test"
    If cbAddress.Checked = True Then
        Dim thetext As String = txtTextbox.Text
        txtTextbox.Text = thetext & Environment.NewLine & theItem
    Else
        txtTextbox.Text = txtTextbox.Text.Replace(Environment.NewLine & theItem, "")
    End If
End Sub
于 2013-08-26T23:35:19.183 回答
0

更换Environment.NewLine

txtTextbox.Text = txtTextbox.Text.Replace(System.Environment.NewLine, "")
于 2013-08-26T20:47:38.440 回答