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 make an incremental search in Grid

Grids

How to make an incremental search in Grid

by  ramani  Posted    (Edited  )
**********************************************************
** How to make an incremental search in Grid.
**********************************************************
** by Subramanian.G (ramani)
** FoxAcc Software
** ramani_g@yahoo.com
**********************************************************

1. Create a form level property (variable), cFilterOld and cFilter

2. Create a text box in the search form and deploy it alongside the navigation bar or at a suitable place. Let us call this text box 'txtSearch'.

3. Key in the following code in the InteractiveChangeEvent of the txtSearch. You can do a cut & paste as well.
**********************************************************
LOCAL cFilterOld, cFilterIn
cFilterOld = ThisForm.cFilterOld
cFilterIn = KEY()

SET FILTER TO

IF LEFT(This.Value,1) = "*"
IF LEN(ALLTRIM(This.Value)) > 1
ThisForm.cFilter = ;
RIGHT(ALLTRIM(This.Value),LEN(ALLTRIM(This.Value))-1)
IF EMPTY(cFilterOld)
SET FILTER TO ThisForm.cFilter $ &cFilterIn
ELSE
SET FILTER TO &cFilterOld .AND. ;
ThisForm.cFilter $ &cFilterIn
ENDIF
LOCATE
ELSE
IF !EMPTY(cFilterOld)
SET FILTER TO &cFilterOld
ENDIF
ENDIF
ELSE
IF !EMPTY(cFilterOld)
SET FILTER TO &cFilterOld
ENDIF
SEEK ALLT(This.Value)
ENDIF

ThisForm.Refresh()
ThisForm.GridBase1.SetFocus
This.SetFocus
**********************************************************
4. Add in the AfterRowColChange event of the Grid (ThisForm.GridBase1)

DODEFAULT()
ThisForm.txtSearch.SetFocus()

The above code will help in setting the focus back, in case, the user clicks the mouse in any cell of the grid.
**********************************************************
5. What we achieve is
a. An interactive search when the user keys in the txtSearch text box.
b. IF THE FIRST CHARACTER OF THE SEARCH IS "*" WILDCARD, then search the key field contents for the presence of the word or letters that follow the wild card.

Hope this is of help :)

Ramani
(Subramanian.G), FoxAcc, ramani_g@yahoo.com
**********************************************************
** EOF
**********************************************************
Evaluate this to make others know how useful is this :)
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top