I never thought this would be this easy.
Conditions are:
1. You have to use displayedit clause.
2. On displaychange event should be ComboSearchAutoFill()
3. Line No. 55 determines whether it is combosearchbox or autofill.
4. Please use 'countries.lst' file from c:\hmg\hfcl\samples\combosearchbox
See the sample for more details and give me your comments.
Code: Select all
#include <hmg.ch>
Function Main
local aCountries := HB_ATOKENS( MEMOREAD( "Countries.lst" ), CRLF )
define window x at 0,0 width 300 height 200 main
define textbox b
row 10
col 10
end textbox
define combobox a
row 60
col 10
width 100
items aCountries
sort .t.
displayedit .t.
on displaychange ComboSearchAutoFill()
on lostfocus x.b.value := x.a.item(x.a.value)
end combobox
end window
x.center
x.activate
Return
function ComboSearchAutoFill
local nHandle := 0
local cValue := this.displayvalue
local nStart := 0
local nFound := 0
nHandle := GetControlHandle (this.name,thiswindow.name)
if .not. valtype(_HMG_SYSDATA [ 296 ]) == "U"
if _HMG_SYSDATA [ 296 ] > 0
if len(cValue) == _HMG_SYSDATA [ 296 ]
if len(cValue) > 1
cValue := substr(cValue,1,len(cValue)-1)
else
nFound := ComboBoxFindString(nHandle,cValue)
if nFound <> -1
ComboBoxSelectString(nHandle,cValue)
ComboBoxEditSetSel(nHandle,0,-1)
_HMG_SYSDATA [ 296 ] := 0
return nil
endif
endif
endif
endif
endif
_HMG_SYSDATA [ 296 ] := len(cValue)
nStart := len(cValue)
if nHandle > 0
// ComboBoxShowDropDown(nHandle)
nFound := ComboBoxFindString(nHandle,cValue)
if nFound <> -1
ComboBoxSelectString(nHandle,cValue)
ComboBoxEditSetSel(nHandle,nStart,-1)
endif
endif
return nil
#pragma BEGINDUMP
#include <windows.h>
#include <commctrl.h>
#include "hbapi.h"
#include <wingdi.h>
HB_FUNC ( COMBOBOXSHOWDROPDOWN )
{
HWND hWnd1;
hWnd1 = (HWND) hb_parnl (1);
SendMessage((HWND) hWnd1,CB_SHOWDROPDOWN, (WPARAM)(int) 1,(LPARAM)(int) 0);
}
HB_FUNC ( COMBOBOXEDITSETSEL )
{
HWND hWnd1;
hWnd1 = (HWND) hb_parnl (1);
hb_retni(SendMessage((HWND) hWnd1,CB_SETEDITSEL, (WPARAM)(int) 0,(LPARAM) MAKELPARAM((int) hb_parni(2),(int) hb_parni(3))));
}
HB_FUNC ( COMBOBOXGETEDITSEL )
{
HWND hWnd1;
DWORD pos;
hWnd1 = (HWND) hb_parnl (1);
pos = SendMessage((HWND) hWnd1,CB_GETEDITSEL, (WPARAM) NULL,(LPARAM) NULL);
hb_reta(2);
hb_storvni ( LOWORD(pos) , -1, 1 );
hb_storvni ( HIWORD(pos) , -1, 2 );
}
HB_FUNC ( COMBOBOXSELECTSTRING )
{
HWND hWnd1;
int n;
hWnd1 = (HWND) hb_parnl (1);
hb_retni(SendMessage((HWND) hWnd1,CB_SELECTSTRING, (WPARAM)(int) -1,(LPARAM) (LPCSTR) hb_parc(2)));
}
HB_FUNC ( COMBOBOXFINDSTRING )
{
HWND hWnd1;
int n;
hWnd1 = (HWND) hb_parnl (1);
hb_retni(SendMessage((HWND) hWnd1,CB_FINDSTRING, (WPARAM)(int) -1,(LPARAM) (LPCSTR) hb_parc(2)));
}
#pragma ENDDUMP