单击复选框时,我在文本框中添加一行。如果单击该复选框并想要删除该项目,我该怎么办:
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
我应该在文本框中跟踪添加到哪一行,以便在取消选中时将其删除,还是有更好的方式?
答案 0 :(得分:0)
替换Environment.NewLine
txtTextbox.Text = txtTextbox.Text.Replace(System.Environment.NewLine, "")
答案 1 :(得分: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