INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Grids

How to make an incremental search in Grid by ramani
Posted: 27 Oct 01 (Edited 16 Dec 02)

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

Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close