2013-08-26 30 views
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 

,我應該跟蹤哪些行被添加到文本框中選中時將其刪除,或者是有更好的辦法?

+0

是在文本框中的文本編輯? –

回答

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 
0

更換Environment.NewLine

txtTextbox.Text = txtTextbox.Text.Replace(System.Environment.NewLine, "") 
+0

在檢查其他東西后,可能會取消選中它。 – iDev

+0

請根據您的情況使用上述行。我不知道你的實現邏輯。 – Krishna

相關問題