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.

Recommended Answers

All 5 Replies

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?

pls do reply me guys..am asking in vb6.0
is there any possible way to do that..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.