ComboSearchBox + AutoFill

HMG Samples and Enhancements

Moderator: Rathinagiri

User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

ComboSearchBox + AutoFill

Post by Rathinagiri »

Here you can see a sample of a combination of ComboSearchBox and AutoFill. :)

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
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: ComboSearchBox + AutoFill

Post by esgici »

Hi Rathi

Tested, worked with no problem, thanks :)

Regards

--

Esgici
Viva INTERNATIONAL HMG :D
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: ComboSearchBox + AutoFill

Post by Rathinagiri »

Thanks Esgici.

This can be easily incorporated in in-place edit also. I am working on that. :)
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
sudip
Posts: 1454
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

Re: ComboSearchBox + AutoFill

Post by sudip »

Hello Rathi,
Excellent :D
Regards.
Sudip
With best regards,
Sudip
User avatar
RIT
Posts: 13
Joined: Mon Oct 04, 2010 1:32 am
Location: Osorno, Chile
Contact:

Re: ComboSearchBox + AutoFill

Post by RIT »

Hi Rathi, a query that is precisely the variable _HMG_SYSDATA [ 296 ] ?

Greetings,
RIT.
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: ComboSearchBox + AutoFill

Post by Rathinagiri »

The length of the currently editing string is stored in _HMG_SYSDATA [ 296 ]. Instead of using a separate public variable, I have used this location allotted by Roberto exclusively for hfcl. Noting special.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
RIT
Posts: 13
Joined: Mon Oct 04, 2010 1:32 am
Location: Osorno, Chile
Contact:

Re: ComboSearchBox + AutoFill

Post by RIT »

Hi Rathi, I have incorporated the following code to the example:

@ 80,110 BUTTON button_1 ;
CAPTION '..' ;
ACTION (SetProperty( "frmAFTest", "txbCountry", "Value", "Chile" )) ;
WIDTH 24 ;
HEIGHT 24

In order to assign a value to textbox, however, I get an empty character.
Greetings,
RIT.
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: ComboSearchBox + AutoFill

Post by Rathinagiri »

Hi RIT,

Can you please post the full/sample code?
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
RIT
Posts: 13
Joined: Mon Oct 04, 2010 1:32 am
Location: Osorno, Chile
Contact:

Re: ComboSearchBox + AutoFill

Post by RIT »

Sure.

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' ;
              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( aCountries )
                 ONGOTFOCUS  AFKeySet( aCountries )
                 ONLOSTFOCUS AFKeyRls(  )
              END TEXTBOX // txbCountry   
              
              @ 80,110 BUTTON button_1 ;
			  CAPTION '..' ; 
			  ACTION  (SetProperty( "frmAFTest", "txbCountry", "Value", "Chile" )) ; 
			  WIDTH 24 ;
    		  HEIGHT 24  


                 
           END WINDOW // frmAFTest
           
           frmAFTest.Center
           
           frmAFTest.Activate

             
        RETU // Main()

        *-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.

        PROC AutoFill( ;              // Auto filling text box
                        aList,;       // Items list
                        nCaller,;     // NIL : OnChange, 1: UP, 2: Down
                        cControlName )
                        
           STATIC cLastVal := '',;
                  n1Result := 0
           
           LOCAL  cFrmName := '',;
                  cTxBname := '',;
                  cTxBValue := '',;     // Text Box Value
                  nCarePos  := 0,;  // Text Box CaretPos
                  cCurval   := ''

           cFrmName := thiswindow.name
           if pcount() == 3
              cTxBName := cControlName
           else
              cTxBName := this.name
           endif
           cTxBValue := GetProperty( cFrmName, cTxBName, "Value" )     // Text Box Value
           nCarePos  := GetProperty( cFrmName, cTxBName, "CaretPos" )  // Text Box CaretPos
             
           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(;
                       aitems )
           Local cFrmName := thiswindow.name,;
                 cTxBName := this.name
                       
           ON KEY UP   OF &cFrmName  ACTION AutoFill(  aitems, 1,cTxBName )
           ON KEY DOWN OF &cFrmName  ACTION AutoFill(  aitems, 2,cTxBName )

        RETU // AFKeySet()

        *-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.

        PROC AFKeyRls( )
           Local cFrmName := thiswindow.name
                       
           RELEASE KEY UP   OF &cFrmName
           RELEASE KEY DOWN OF &cFrmName

        RETU // AFKeyRls()

        *-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.
           
HMG3035.
Greetings,
RIT.
User avatar
zolysoftsolutions
Posts: 139
Joined: Wed Feb 29, 2012 3:33 am
Location: Gyulakuta, Erdélyország
Contact:

Re: ComboSearchBox + AutoFill

Post by zolysoftsolutions »

Hello Rathi,

I am using this combosearchbox, and is very very usefull, thank you a lot for this.
But my question is still if I can in some way to use this "combosearchbox" in a grid (as a columncontrol)?

Best regards,
Zoli B.

WinXP32, HMG 3.1.1
_______________________________
Open eyes for you!
Post Reply