Click here to Skip to main content
15,886,728 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello I am using stringreader to read strings of data from a richtextbox. Data is being added to the richtextbox and I need to show the new added line when its added to a label so that the label will change when a new line is added to the richtextbox. something like read to end for streamreader.

please help I am unsure what loop to use in this case

thank you in advance


Here is what i have tried but for some reason i only get the first added entry. the next added entry does not show in the label

VB
Dim reader As New StringReader(RichTextBox2.Text)
        Dim tmp As String = reader.ReadToEnd
 Dim MD As Match = md.Match(tmp)
For Each M As String In RichTextBox2.Lines
           If M.Contains(MD.ToString) Then
               Label4.Text = MD.ToString
           End If
       Next M
Posted
Updated 30-Jul-13 21:18pm
v3
Comments
Prasad Khandekar 31-Jul-13 1:59am    
Why not simply use Label.Text = RichtextBox.Text

Regards,
Draco2013 31-Jul-13 2:02am    
because that will show all text i only wish to show the newly added line
Prasad Khandekar 31-Jul-13 2:24am    
If you know the old value of RichTextBox, Which I am sure you will, then it's relatively easy. Just use code something like shown below.

strNewVal = RichTextBox.Text
Label.Text = strNewVal.SubString(strOldValue.Length + 1)

Regards
Draco2013 31-Jul-13 2:35am    
the old value is not stored in any string or variable how am i to call stroldvalue.length +1? also would that not count the string length as a integer?
Draco2013 31-Jul-13 2:38am    
new strings are added to the richtextbox from another source. I am unaware of the new values until they are added. all i am looking to do is add the newly added item to a label and when the next new value is added to the richtextbox the label will display that value changing it

1 solution

When you get all lines in RichTextBox2.Lines.

To get the last line added why don't you use.

string str = RichTextBox2.Lines[RichTextBox2.Lines.Length - 1];
 
Share this answer
 
Comments
Draco2013 31-Jul-13 3:05am    
I tried this but get numbers.... :( i am not looking to count the length of the string lol im not sure you understand my question
Draco2013 31-Jul-13 3:18am    
I have updated the code in hopes someone can see what i am trying to do

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900