Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Read and delete lines
#5
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!
My Blog | My Setup | My Videos | Have a wonderful day.


Messages In This Thread
Read and delete lines - by brco900033 - 09-14-2012, 10:27 AM
Re: Read and delete lines - by brco900033 - 09-14-2012, 10:41 AM
Re: Read and delete lines - by brco900033 - 09-15-2012, 06:10 AM
Re: Read and delete lines - by brandonio21_phpbb3_import2 - 09-15-2012, 10:50 AM
Re: Read and delete lines - by brco900033 - 09-16-2012, 09:07 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I read a link from mysql databse??? mnxford 9 31,151 04-12-2013, 06:27 PM
Last Post: brandonio21
  Convert 2 lines to one brco900033 2 11,239 02-23-2013, 11:04 AM
Last Post: brco900033
  How do I use Listview to delete MySQL DB records kismetgerald 10 32,137 11-28-2012, 05:19 PM
Last Post: brandonio21
  Read certain lines brco900033 3 13,985 09-26-2012, 03:56 PM
Last Post: brandonio21
  How to write string query on multiple lines kismetgerald 1 8,581 08-29-2012, 04:01 PM
Last Post: brandonio21

Forum Jump:


Users browsing this thread: 1 Guest(s)