Question how to find the line number?

saichong

Member
Joined
Nov 21, 2009
Messages
10
Programming Experience
Beginner
hi all

i am using
VB.NET:
For Each line As String In Me.RichTextBox1.Lines
            If line.Contains(TextBox1.Text) Then
                RichTextBox1.Select(startindex, line.Length)
                TextBox2.Text = RichTextBox1.SelectedText
            End If
            startindex += line.Length + 1
Next

but i want to know how to find the number of line that contain my search result?
 
Take a look at the documentation for the RichTextBox. I can't remember the names off-hand but it has lots of methods for finding line and character numbers in various ways.
 
RichTextBox.GetLineFromCharIndex Method (System.Windows.Forms)

or
VB.NET:
For lineNum As Integer = 0 To Me.RichTextBoxData.Lines.Count - 1
    Dim line As String = Me.RichTextBoxData.Lines(lineNum)
    If line.Contains(SearchTextBox.Text) Then
        ResultsTextBox.AppendText((lineNum + 1) & ": " & line & vbNewLine)
    End If
Next
Note the control naming ;)
 
Back
Top