**********************************************************
** 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
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.