Click here to Skip to main content
15,910,471 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello to all,
I need a help with filtering data in RichTextBox by some strings from DataGridView.
I have an report of the all currently used network licenses of an software, so I need to check are the all of the users who used the license my colleagues or not. I have created msaccess database of the machines of my colleagues and now I want to filter report. If the user in the report content is already in the DataGridView column "Machines" then color it as green and all other color as red.
All names of the machines has string "@" in the middle so I would like to use that string to filter value.

For example pasted report is:
https://s26.postimg.org/ilh92zwu1/report_content.png
Here is my form:
https://s26.postimg.org/673nu5k3d/form.png
Here is what I expect:
https://s26.postimg.org/5iutb7ldl/after_filetring.png

Any help is very appreciated.

What I have tried:

Private getnumber As String = "@"

Private Sub RichTextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles RichTextBox1.TextChanged

    For Each row As DataGridViewRow In DataGridView1.Rows
        Dim filteredText As String = row.Cells(2).Value

        For Each m As Match In Regex.Matches(RichTextBox1.Text, getnumber)
            'what?
        Next

    Next


End Sub
Posted
Updated 12-Sep-17 22:31pm

1 solution

Here is a step-by-step video that will show you how to get started: VB.NET - How To Search And Select Text In RichTextBox Using Visual Basic .Net [with source code] - YouTube[^]
 
Share this answer
 
Comments
blueye89 13-Sep-17 7:19am    
I have modified code little bit and it works fine but I would like to get little bit different result. I want to set back color on whole text line where string is filtered, not just on filtered string.
RichTextBox1.SelectAll()
RichTextBox1.SelectionBackColor = Color.Red

For Each row As DataGridViewRow In DataGridView1.Rows

Dim filteredText As String = row.Cells(2).Value
Dim startText As Integer = 0
Dim endText As Integer

endText = RichTextBox1.Text.LastIndexOf(filteredText)

RichTextBox1.SelectAll()



While startText < endText

RichTextBox1.Find(filteredText, startText, RichTextBox1.TextLength, RichTextBoxFinds.MatchCase)
RichTextBox1.SelectionBackColor = Color.GreenYellow

startText = RichTextBox1.Text.IndexOf(filteredText, startText) + 1
End While
Next

Here is the result what I get:
https://s26.postimg.org/7pux4ri7t/img02.png
Here is what I expect:
https://s26.postimg.org/5iutb7ldl/after_filetring.png

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