Thanks my friends Rathi and Sudip ; but sorry, IMO neither working perfect nor everything is fine
Because from user perspective there are some confusing situations: under some conditions back space and delete keys seems not working
Anyway here is new version localized UP and DOWN arrow keys by using Rathi's method.
Code: Select all
/*
AutoFill in Text Box try
Started by Esgici
Enhanced by Roberto Lopez and Rathinagiri
2009.05.10
*/
#include "minigui.ch"
PROC Main()
aCountries := HB_ATOKENS( MEMOREAD( "Countries.lst" ), CRLF )
ASORT( aCountries ) // This Array MUST be sorted
DEFINE WINDOW frmAFTest ;
AT 0,0 ;
WIDTH 550 ;
HEIGHT 300 ;
TITLE 'AutoFill in Text Box try (BE2)' ;
MAIN
ON KEY ESCAPE ACTION frmAFTest.Release
DEFINE LABEL lblCountry
ROW 50
COL 50
VALUE "Country :"
RIGHTALIGN .T.
AUTOSIZE .T.
END LABEL // lblCountry
DEFINE TEXTBOX txbCountry
ROW 48
COL 110
ONCHANGE AutoFill( ThisWindow.Name, This.Name, aCountries )
ONGOTFOCUS AFKeySet( ThisWindow.Name, This.Name, aCountries )
ONLOSTFOCUS AFKeyRls( ThisWindow.Name )
END TEXTBOX // txbCountry
END WINDOW // frmAFTest
frmAFTest.Center
frmAFTest.Activate
RETU // Main()
*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.
PROC AutoFill( ; // Auto filling text box
cFrmName ,; // Form / Windows name
cTxBName ,; // Text Box Name
aList,; // Items list
nCaller ) // NIL : OnChange, 1: UP, 2: Down
STATIC cLastVal := '',;
n1Result := 0
LOCAL cTxBValue := GetProperty( cFrmName, cTxBName, "Value" ),; // Text Box Value
nCarePos := GetProperty( cFrmName, cTxBName, "CaretPos" ),; // Text Box CaretPos
cCurval := ''
IF HB_ISNIL( nCaller )
IF !( cLastVal == cTxBValue )
cCurval := LEFT( cTxBValue, nCarePos )
IF !EMPTY( cCurval )
n1Result := ASCAN( aList, { | c1 | UPPER( LEFT( c1, LEN( cCurval ) ) ) == UPPER( cCurval )} )
IF n1Result > 0
cCurval := aList[ n1Result ]
ENDIF n1Result > 0
ENDIF !EMPTY( cCurval )
cLastVal := cCurval
AF_Apply( cFrmName, cTxBName, cCurval, nCarePos )
ENDIF cLastVal # cCurval
ELSE
IF n1Result > 0
IF nCaller < 2
n1Result -= IF( n1Result > 1, 1, 0 )
ELSE
n1Result += IF( n1Result < LEN( aList ), 1, 0 )
ENDIF
cCurval := aList[ n1Result ]
cLastVal := cCurval
AF_Apply( cFrmName, cTxBName, cCurval, nCarePos )
ENDIF n1Result > 0
ENDIF HB_ISNIL( nCaller )
RETU // AutoFill()
*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.
PROC AF_Apply( ;
cFrmName,;
cTxBName,;
cValue,;
nPosit )
SetProperty( cFrmName, cTxBName, "Value", cValue )
SetProperty( cFrmName, cTxBName, "CaretPos", nPosit )
RETU // AF_Apply()
*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.
PROC AFKeySet(;
cFrmName ,;
cTxBName ,;
aitems )
ON KEY UP OF &cFrmName ACTION AutoFill( cFrmName, cTxBName, aitems, 1 )
ON KEY DOWN OF &cFrmName ACTION AutoFill( cFrmName, cTxBName, aitems, 2 )
RETU // AFKeySet()
*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.
PROC AFKeyRls( ;
cFrmName )
RELEASE KEY UP OF &cFrmName
RELEASE KEY DOWN OF &cFrmName
RETU // AFKeyRls()
*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.
Regards
--
Esgici