I have a MSHFlexGrid that gets all records via a recordset from a database.
I want to add a search function so that it would search for the data entered by the user on to the search textbox. But it should search for the data only in a certain column in the MSHFlexGrid.
Can anyone please give me the code for this?

And I'm very sorry if the question is not clear. If it is not, please inform me. I will do my best to make it more understandable.

5 Years
Discussion Span
Last Post by jamunadevi.v

Lets presume that you are searching for a id in coloumn 1 of your grid -

Dim xString As String, xRow As Integer, xNext As Integer

xString = txtSearch.Text

For xNext = 0 To mshFlexgrid.Rows ''Use -1 if you do not have titles in the first row and data starts from the first row...
    mshFlexgrid.Row = xNext ''Sets the row to the current loop number...
    xRow = mshFlexgrid.Row

    If xString = mshFlexgrid.TextMatrix(xRow, 1) ''Assuming that the string is in coloumn 1...
        ''Do whatever you need to do here...
        Msgbox "Record found here."

        Exit For
    End If
Next xNext

the code works great!
but one more small question.
Is there anyway that i can highlight the row that is found by the search on the MSHFlexGrid?


Yes, use something like this in the loop statement... -

Dim i as Integer 
With Grid
    .Row = .MouseRow 
    For i = 1 to .cols-1
     .Col = i
     .CellBackColor = RGB(255,0,0 ) 'red
End Grid

my doubt Is there anyway that i can highlight the word that is found by the search on the MSHFlexGrid?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.