How can I implement an incremental lookup as soon as I open a database browse ?
How can I implement an incremental lookup as soon as I open a database browse ?
Please review
Antonio:
Thank you for your help. I tried the program in the thread that you specified but I noticed that it only looks on one character type by the user. For example, if I want to look up the name Alfred, after typing the letter A, I cannot continue to type the rest of the name, thus not doing an incremental search.
#include "FiveWin.ch"
REQUEST DBFCDX
function Main()
local oWnd, oBrw, hBmp := ReadBitmap( CurDir() + "\go.bmp" )
local oSay, cSearch := ""
USE ( CurDir() + "\Customer" ) VIA "DBFCDX"
if ! File( CurDir() + "\LAST.CDX" )
INDEX ON Customer->Last TO ( CurDir() + "\LAST" )
endif
Customer->( OrdSetFocus( "LAST" ) )
Customer->( DbGoTop() )
DEFINE WINDOW oWnd TITLE "IncSearch"
@ 1, 1 LISTBOX oBrw ;
FIELDS hBmp, Customer->Last, Customer->First ;
HEADERS "", "Last", "First" ;
SIZE 220, 167
oBrw:bKeyChar = { | nKey, nFlags | Search( nKey, @cSearch ), oBrw:Refresh(),;
oSay:Refresh() }
@ 14, 2 SAY "Searching:" SIZE 60, 30
@ 14, 12 SAY oSay PROMPT cSearch SIZE 80, 30
ACTIVATE WINDOW oWnd ;
ON CLICK MsgInfo( "Click!" )
return nil
function Search( nKey, cSearch )
if nKey = 8
cSearch = SubStr( cSearch, 1, Len( cSearch ) - 1 )
else
cSearch += Upper( Chr( nKey ) )
endif
Customer->( DbSeek( cSearch, .t. ) )
return nil @ <nRow>,<nCol> SAY oBrw:oSeek PROMPT oBrw:cSeek SIZE
<nWidth>,<nHeight> PIXEL OF oDlg//--------------------------------------------
#include "FiveWin.ch"
#include "xbrowse.ch"
REQUEST DBFCDX
function Main()
local oDlg, oBrw, oFont
CheckIndexes() // required only for this sample
USE CUSTOMER SHARED VIA "DBFCDX"
Customer->( OrdSetFocus( "FIRST" ) )
Customer->( DbGoTop() )
DEFINE FONT oFont NAME 'TAHOMA' SIZE 0,-14
DEFINE DIALOG oDlg SIZE 600,600 PIXEL ;
TITLE "XBrowse Incremental Seek" ;
FONT oFont
@ 10,10 XBROWSE oBrw ;
SIZE 280,230 PIXEL ;
OF oDlg ;
ALIAS "CUSTOMER" ;
AUTOCOLS AUTOSORT LINES CELL
@ 250,10 SAY oBrw:oSeek PROMPT oBrw:cSeek SIZE 280,10 PIXEL OF oDlg ;
COLOR CLR_BLACK, CLR_YELLOW
oBrw:CreateFromCode()
ACTIVATE DIALOG oDlg CENTERED
RELEASE FONT oFont
return nil
//-----------------------------------------------------------------------------//
*
* following code is only for the sample
*
*
static function CheckIndexes()
local n
if File( "customer.cdx" )
FErase( "customer.cdx" )
endif
USE CUSTOMER EXCLUSIVE VIA "DBFCDX"
for n := 1 to FCount()
CreateTag( FieldName( n ) )
next
USE
return nil
//----------------------------------------------------------------------------//
static function CreateTag( ctag )
INDEX ON &ctag TAG &ctag
return nil
//----------------------------------------------------------------------------//Antonio:
Kudos ! Great example, superb, magnífico ! Your xbrowse class is very welcome !
Antonio:
Why after typing an argument for the incremental search, if the user navigate the browse with the up/down arrows, the cSeek / oSeek variables loses their data ? Can this be avoided ? Thank you