09-15-2012, 10:50 AM
Ah, alright! Well this solution is rather fancy, if I don't say so myself.
So, I have created this method that completely removes a line from the textbox which contains a specified value.
[code2=vbnet]Public Sub RemoveLine(ByVal containing As String)
If (TextBox1.Text.Contains(containing)) Then
'Now, we need to find which line index contains the thing
Dim lineIndex As Integer = TextBox1.GetLineFromCharIndex(TextBox1.Text.IndexOf(containing))
'Now, let's delete that line
Dim lines As New List(Of String)
lines.AddRange(TextBox1.Text.Split(vbNewLine))
lines.RemoveAt(lineIndex)
'Now, reset the text
TextBox1.Text = String.Join(vbNewLine, lines.ToArray, 0, lines.Count)
End If
End Sub[/code2]
So, if you want to delete a line containing whatever TextBox2.Text has in it, for example, add a button to your form (Button1), then, just call this code from your button:
[code2=vbnet]RemoveLine(TextBox2.Text)[/code2]
Hopefully this works for you!
So, I have created this method that completely removes a line from the textbox which contains a specified value.
[code2=vbnet]Public Sub RemoveLine(ByVal containing As String)
If (TextBox1.Text.Contains(containing)) Then
'Now, we need to find which line index contains the thing
Dim lineIndex As Integer = TextBox1.GetLineFromCharIndex(TextBox1.Text.IndexOf(containing))
'Now, let's delete that line
Dim lines As New List(Of String)
lines.AddRange(TextBox1.Text.Split(vbNewLine))
lines.RemoveAt(lineIndex)
'Now, reset the text
TextBox1.Text = String.Join(vbNewLine, lines.ToArray, 0, lines.Count)
End If
End Sub[/code2]
So, if you want to delete a line containing whatever TextBox2.Text has in it, for example, add a button to your form (Button1), then, just call this code from your button:
[code2=vbnet]RemoveLine(TextBox2.Text)[/code2]
Hopefully this works for you!