I think I had solved this backspace problem too.
Code: Select all
/*
AutoFill in Text Box try
*/
#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' ;
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
ongotfocus autofill_init(acountries)
ONCHANGE AutoFill(aCountries )
onlostfocus autofill_close()
END TEXTBOX // txbCountry
define listbox list1
row 80
col 110
width 200
items {"Item 1","Item 2","Item 3","Item 4","Item 5","Item 6"}
value 1
end listbox
END WINDOW // frmAFTest
frmAFTest.Center
frmAFTest.Activate
RETU // Main()
*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.
PROC AutoFill( ; // Setting CSBox values
aList) //Items list
LOCAL cCurval := '' ,;
n1Result := 0,;
cFrmName := thiswindow.name,;
cTxBName := this.name,;
nCarePos := this.caretpos
cCurval := LEFT( GetProperty( cFrmName, cTxBName, "Value" ), nCarePos )
IF !EMPTY( cCurval )
n1Result := ASCAN( aList, { | c1 | UPPER( LEFT( c1, LEN( cCurval ) ) ) == UPPER( cCurval )} )
IF n1Result > 0
cCurval := aList[ n1Result ]
ENDIF n1Result > 0
SetProperty( cFrmName, cTxBName, "Value", cCurval )
// SetProperty( cFrmName, cTxBName, "CaretPos", nCarePos )
SendMessage ( GetControlHandle(cTxBname,cFrmName) , 177 , len(cCurval),ncarepos )
ENDIF !EMPTY( cCurval )
if ncarepos == 0 .and. len(alltrim(GetProperty( cFrmName, cTxBName, "Value" ))) > 0
if ascan(alist,{ | c1 | UPPER( c1 ) == UPPER( GetProperty( cFrmName, cTxBName, "Value" ) )}) == 0
SetProperty( cFrmName, cTxBName, "Value", '' )
endif
endif
RETU // SetCSBoxVal()
*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.
PROC AFNavigate( ; // Navigation by UP/DOWN keys in AutoFill Text Box
nDirect ,; // 1 : Up, 2: Down
cFrmName,;
cTxBName,;
aList ) // Items list
LOCAL nCarePos := GetProperty( cFrmName, cTxBName, "CaretPos" ),;
n1Result := 0
LOCAL cCurval := LEFT( GetProperty( cFrmName, cTxBName, "Value" ), nCarePos )
IF !EMPTY( cCurval )
n1Result := ASCAN( aList, { | c1 | UPPER( LEFT( c1, LEN( cCurval ) ) ) == UPPER( cCurval )} )
IF n1Result > 0
IF nDirect < 2
n1Result -= IF( n1Result > 1, 1, 0 )
ELSE
n1Result += IF( n1Result < LEN( aList ), 1, 0 )
ENDIF
cCurval := aList[ n1Result ]
ENDIF n1Result > 0
SetProperty( cFrmName, cTxBName, "Value", cCurval )
SetProperty( cFrmName, cTxBName, "CaretPos", nCarePos )
ENDIF !EMPTY( cCurval )
RETU // AFNavigate()
*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.
function autofill_init(aitems)
local formname := thiswindow.name
local controlname := this.name
ON KEY UP of &formname ACTION AFNavigate( 1, formname, controlname, aitems )
ON KEY DOWN of &formname ACTION AFNavigate( 2, formname, controlname, aitems )
ON KEY BACK of &formname ACTION autofilldobackspace(formname,controlname,aitems)
return nil
function autofill_close
local formname := thiswindow.name
release key UP of &formname
release key DOWN of &formname
return nil
function autofilldobackspace(formname,controlname,alist)
local nstart := LoWord ( SendMessage( GetControlHandle(controlname,formname) , 176 , 0 , 0 ) )
local nend := HiWord ( SendMessage( GetControlHandle(controlname,formname) , 176 , 0 , 0 ) )
local ccurvalue := getproperty(formname,controlname,"VALUE")
local n1Result := 0
if nstart > 0
n1Result := ASCAN( aList, { | c1 | UPPER( LEFT( c1, nstart-1 ) ) == UPPER( substr(cCurvalue,1,nstart-1 ))} )
IF n1Result > 0
ccurvalue := aList[ n1Result ]
ENDIF n1Result > 0
setproperty(formname,controlname,"VALUE",ccurvalue)
SendMessage ( GetControlHandle(controlname,formname) , 177 , len(ccurvalue),nstart-1 )
endif
return nil