I have tried in MsFlexGrid. May be the same procedure you can use it for DataGrid. Try This out.
1. Place a MsFlexGrid on the form and name it as Grd
2. Place a text box for the text you want to have search.
Name it as txtSearch
3. On txtSearch_Change event write the following code
Private Sub txtSearch_Change()
Dim colm As Integer
Dim i As Long
For i = 0 To 1
Grd.cOL = i
Grd.CellBackColor = &HC0FFFF
Grd.CellForeColor = vbBlack
Next i
Grd.cOL = 1
For i = 1 To Grd.Rows - 1
If Mid(UCase(Trim(txtSearch.Text)), 1, Len(UCase(Trim(txtSearch.Text)))) = Mid(Trim(Grd.Text), 1, Len(UCase(Trim(txtSearch.Text)))) Then
Grd.TopRow = Grd.Row
Exit For
End If
Grd.Row = i
Next i
For i = 0 To Grd.Cols - 1
Grd.cOL = i
Grd.CellBackColor = vbRed
Grd.CellForeColor = &HC0FFFF
Next i
End Sub
This will hightlight the search text result with Red Color.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.