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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Search in a DataGrid

Status
Not open for further replies.

Jekel

Programmer
Feb 9, 2002
1
0
0
US
I cant get my program to search records in a datagrid if anyone knows a easy way to do this please respond
 
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.

May be this procedure can be used for DataGrid.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top