Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MsFlexgrid -Searching for String within. 1

Status
Not open for further replies.

vbmorton

Technical User
Dec 27, 2004
44
US
Hi Everyone,
I have a msFlexgrid, in which i am allowing users via a input field to type a value (ie.. new) and what i want it to do, is go into the msFlexgrid col(2) which is a miscellaneous description column so it could have many words in it, and based on the user inputs ie we, it to go thru the grid col(2) for all the records in it until it finds that word new.. the description that it should highlight and bring the entire row, of which it found this word to top of grid. (ie.. this is a new part that we are trying to implement.)

this is what i have so far. so far it goes thru the grid but only matches on entire cell, not the string within.

Code:
Private Sub cmdFind_Click()
Dim target_name As String
Dim r As Integer

    ' Get the name.
    target_name = InputBox("Name", "Name", "")
    If Len(target_name) = 0 Then Exit Sub

    ' Search for the name, skipping the column heading row.
    target_name = LCase$(target_name)
    For r = 1 To grdSupportCalls.Rows - 1
        If LCase$(grdSupportCalls.TextMatrix(r, 2)) = target_name Then
            ' We found the target. Select this row.
            grdSupportCalls.Row = r
            grdSupportCalls.RowSel = r
            grdSupportCalls.Col = 0
            grdSupportCalls.ColSel = grdSupportCalls.Cols - 1

            ' Make the row visible.
            grdSupportCalls.TopRow = r
            Exit Sub
        End If
    Next r

    ' We didn't find it.
    Beep
 
End Sub


Thanks VBMORTON
 
Have you tried the InStr() function?

zemp
 
Zemp,

you da man! works perfectly!!!

changed it to this.
Code:
target_name = LCase$(target_name)
    For r = 1 To grdSupportCalls.Rows - 1
        search_name = LCase$(grdSupportCalls.TextMatrix(r, 2))
        pos = InStr(search_name, target_name)
        
        If pos > 0 Then


 
Zemp,

one more question.. what i want to have happen is if the row does not contain the search criteria, i dont want it to show up in the table.. , the table i want it to be a listing of all rows that have that match to the search string.


how would i do that.
can you give me an example with above code?

thanks,

VBMORTON

 
If you don't want to refill the grid with only the relevant data (which would be my first choice) then the easiest thing might be to set the .rowheight of rows that don't have the search data to zero (0).

Something like this,
Code:
target_name = LCase$(target_name)
    For r = 1 To grdSupportCalls.Rows - 1
        search_name = LCase$(grdSupportCalls.TextMatrix(r, 2))
        pos = InStr(search_name, target_name)
        
        If pos > 0 Then
          grdSupportCalls.RowHeight(r) = 255 'normal 
        Else
          grdSupportCalls.RowHeight(r) = 0
        End If



zemp
 
thanks zemp for the quick response..
That works pretty good.. so easy. i was thinking a remove.. glad you were here to assist.


thanks

vbmorten
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top