editable combobox con busqueda incremental

User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

editable combobox con busqueda incremental

Post by Antonio Linares »

Alguien está usando un combobox editable y que soporte búsqueda incremental ?

FWH soporta búsqueda incremental en comboboxes no editables, y estoy buscando la forma de implementarlo, gracias!
regards, saludos

Antonio Linares
www.fivetechsoft.com
Ariel
Posts: 309
Joined: Wed Nov 29, 2006 1:51 pm
Location: Rosario - Argentina

Re: editable combobox con busqueda incremental

Post by Ariel »

Antonio,
estaria bueno implementar un xbrowse enganchado con el combobox, eso le daria una potencia increible al combo.

Salu2, Ariel.
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: editable combobox con busqueda incremental

Post by Antonio Linares »

Ariel,

Cierto, pero de momento se trata de resolver lo que explico :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
karinha
Posts: 4882
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: editable combobox con busqueda incremental

Post by karinha »

João Santos - São Paulo - Brasil
User avatar
karinha
Posts: 4882
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: editable combobox con busqueda incremental

Post by karinha »

http://forums.fivetechsupport.com/viewt ... =3&t=28456

ó algo asi?


Code: Select all

#Include "FiveWin.Ch"
#include "xbrowse.ch"

Function Main()
   Local oDlg
   Local oGet, oGet1, oCb
   local cVar := space( 20 )
   local a := {}

   USE customer NEW 
   customer -> ( DBEVAL( {|| AADD( a, field -> street ) } ) )

   DEFINE DIALOG oDlg from 0,0 to 400,400 pixel
   
   oGet := tListGet():new(15,15,{ | u | If( PCount()==0, cVar, cVar:= u ) },oDlg,120,12,"@!",,,,,,,.T.)
      
   @ 29,15 get oGet1 var cVar picture "@!" size 120,12 of oDlg pixel

   @ 43,15 COMBOBOX oCb ITEMS a OF oDlg pixel SIZE 120,100

   oGet:aSource  := a
   oGet:bSearch  := {|i,e| AT( i, UPPER(e) ) > 0 }
   oGet:cSource  := 'ARRAY'
   oGet:lenDisplay := 15
   
   ACTIVATE DIALOG oDlg 
 
   USE

return nil

//--------------------------------------------------------------- 

CLASS tListGet FROM tGet

   DATA   oBrw, oWin, aData, lenBuffer, bSearch, aSource, cSource, cField, cAlias, lenDisplay

   METHOD new() CONSTRUCTOR
   METHOD redefine() CONSTRUCTOR
   METHOD FillList()
   METHOD Initiate()
   METHOD keyDown()
   METHOD keychar()

ENDCLASS 

//--------------------------------------------------------------- 
METHOD New( nRow, nCol, bSetGet, oWnd, nWidth, nHeight, cPict, bValid,;
            nClrFore, nClrBack, oFont, lDesign, oCursor, lPixel, cMsg,;
            lUpdate, bWhen, lCenter, lRight, bChanged, lReadOnly,;
            lPassword, lNoBorder, nHelpId, lSpinner,;
            bUp, bDown, bMin, bMax, bAction, cBmpName, cVarName, cCueText ) CLASS tListGet  
//--------------------------------------------------------------- 

RETURN ::super:new( nRow, nCol, bSetGet, oWnd, nWidth, nHeight, cPict, bValid,;
            nClrFore, nClrBack, oFont, lDesign, oCursor, lPixel, cMsg,;
            lUpdate, bWhen, lCenter, lRight, bChanged, lReadOnly,;
            lPassword, lNoBorder, nHelpId, lSpinner,;
            bUp, bDown, bMin, bMax, bAction, cBmpName, cVarName, cCueText )
//--------------------------------------------------------------- 

METHOD ReDefine( nId, bSetGet, oWnd, nHelpId, cPict, bValid, nClrFore,;
                 nClrBack, oFont, oCursor, cMsg, lUpdate, bWhen, bChanged,;
                 lReadOnly, lSpinner, bUp, bDown, bMin, bMax, bAction, cBmpName,;
                 cVarName, cCueText ) CLASS tListGet
//--------------------------------------------------------------- 

RETURN ::super:ReDefine( nId, bSetGet, oWnd, nHelpId, cPict, bValid, nClrFore,;
                 nClrBack, oFont, oCursor, cMsg, lUpdate, bWhen, bChanged,;
                 lReadOnly, lSpinner, bUp, bDown, bMin, bMax, bAction, cBmpName,;
                 cVarName, cCueText )
    
//--------------------------------------------------------------- 
METHOD Initiate( hDlg ) CLASS TListGet
//--------------------------------------------------------------- 
LOCAL oSelf := SELF, aRect

   ::super:Initiate( hDlg )

   ::lenBuffer          := LEN( cValToChar( Eval( ::bSetGet ) ) )
   ::aData              := ARRAY(1)
   DEFAULT ::lenDisplay := 5

   DEFINE DIALOG ::oWin OF oSelf:oWnd FROM 100, 100 TO 100, 100 + ::nWidth PIXEL STYLE nOR( WS_CHILD, WS_POPUP, WS_VISIBLE )

   @ 0, 0 XBROWSE ::oBrw OF oSelf:oWin ARRAY oSelf:aData COLUMNS 1 SIZEs ::nWidth

   ::oBrw:lHeader         := .F.
   ::oBrw:lRecordSelector := .F.
   ::oBrw:lFlatStyle      := .T.
   ::oBrw:nStyle    -= WS_BORDER
   ::oWin:oClient   := ::oBrw
   ::oBrw:bChange   := {|| ::cText( PADR( ::aData[ ::oBrw:nArrayAt ], ::lenBuffer, ' ' ) ), ::refresh(), ::SetPos( LEN( ALLTRIM( ::aData[ ::oBrw:nArrayAt ] ) ) + 1 ), ::setFocus() }
   ::oBrw:bLClicked := {|| ::oWin:hide() }
   ::oBrw:lHScroll  := .F.
   ::oBrw:lVScroll  := .F.
   ::oBrw:createFromCode()
  
   ::bPostKey     := {|oGet, cBuffer| ;
              IF( EMPTY( cBuffer ), ::oWin:hide(), NIL  ),;
                      oGet:aData[1] := cBuffer, ;
              oGet:Assign(), ;
              ::FillList() }
                
  ACTIVATE DIALOG oSelf:oWin NOWAIT ON INIT oSelf:oWin:hide()

  ::oWnd:bMoved := {|| ::oWin:hide() }

return nil

//--------------------------------------------------------------- 
METHOD FillList() CLASS TListGet
//--------------------------------------------------------------- 
LOCAL i := 1, aRect

       ASIZE( ::aData, 1 )
       DO CASE
          CASE ::cSource = 'ARRAY'
               DO WHILE  LEN( ::aData ) < ::lenDisplay .AND. i <= LEN( ::aSource )
                  IF EVAL( ::bSearch, ALLTRIM(::aData[1]), ::aSource[i] )
                 AADD( ::aData, ::aSource[i] )
              ENDIF
                  i++
               ENDDO
           ::oWin:SetSize( ::oWin:nWidth, ( LEN( ::aData ) ) * GetTextHeight( ::hWnd ) + LEN( ::aData ) )
               aRect := getWndRect( ::hWnd ) 
           ::oWin:move( aRect[1] + ::nHeight + 3, aRect[2] ) 
           ::oWin:show()
          CASE ::cSource = 'DBF'
               (::cAlias) -> ( DBGOTOP() )
               DO WHILE  LEN( ::aData ) < ::lenDisplay .AND. ! (::cAlias)-> ( EOF() )
                  IF EVAL( ::bSearch, ALLTRIM(::aData[1]), (::cAlias)-> ( fieldGet( fieldPos( ::cField ) ) ) )
                 AADD( ::aData, (::cAlias)-> ( fieldGet( fieldPos( ::cField ) ) ) )
              ENDIF
                  i++
               ENDDO
       ENDCASE

       ::oBrw:refresh()

RETURN NIL

//--------------------------------------------------------------- 
METHOD KeyDown( nKey, nFlags ) CLASS TListGet
//--------------------------------------------------------------- 

   IF ::oWin:lVisible
      DO CASE
         CASE nKey == VK_UP
          ::oBrw:GoUp()
          RETURN 0

         CASE nKey == VK_DOWN
          ::oBrw:GoDown()
          RETURN 0
      ENDCASE
   ENDIF

   IF nKey == VK_DELETE .or. nKey == VK_BACK
      Super:KeyDown( nKey, nFlags )
      ::aData[1] := ::cText()
      IF( EMPTY( ::aData[1] ), ::oWin:hide(), ::FillList() )
      RETURN 0
   ENDIF   

RETURN Super:KeyDown( nKey, nFlags )

//--------------------------------------------------------------- 
METHOD keychar( nKey, nFlags ) CLASS TListGet
//--------------------------------------------------------------- 

           IF nKey == VK_RETURN .AND. ::oWin:lVisible
          ::oWin:hide()
       ENDIF
       
RETURN super:keychar( nkey, nFlags )
 
João Santos - São Paulo - Brasil
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: editable combobox con busqueda incremental

Post by Antonio Linares »

João,

La idea es usar un combobox dropdown list estandard.

Lo primero que he intentado ha sido esto:

Code: Select all

oCbx:oGet:bKeyChar = { | nKey, nFlags | oCbx:KeyChar( nKey, nFlags ) }
Pero nose comportaba como necesito. Luego asi:

Code: Select all

   oCbx:oGet:bKeyChar = { | nKey, nFlags, nAt | ;
       If( ( nAt := AScan( oCbx:aItems, AllTrim( oCbx:oGet:GetText() ) ) ) != 0,;
          ( oCbx:oGet:SetText( oCbx:aItems[ nAt ] ), 0 ), ) }
Pero nada aún :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
karinha
Posts: 4882
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: editable combobox con busqueda incremental

Post by karinha »

João Santos - São Paulo - Brasil
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: editable combobox con busqueda incremental

Post by Antonio Linares »

Joao,

Solucionado :-)

oCbx:oGet:bKeyChar = { | nKey | oCbx:GetKeyChar( nKey ) }

gracias!
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
sysctrl2
Posts: 833
Joined: Mon Feb 05, 2007 7:15 pm
Contact:

Re: editable combobox con busqueda incremental

Post by sysctrl2 »

Hola Antonio,
tienes un ejemplo de como funciona ?

gracias

saludos..
Cesar Cortes Cruz
SysCtrl Software
Mexico

' Sin +- FWH es mejor "
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: editable combobox con busqueda incremental

Post by Antonio Linares »

César,

Code: Select all

#include "FiveWin.ch"

function Main()

   local oDlg, oCbx, cDia

   DEFINE DIALOG oDlg

   @ 1, 3 COMBOBOX oCbx VAR cDia OF oDlg SIZE 100, 300 ;
      ITEMS { "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado", "Domingo" } ;
      STYLE CBS_DROPDOWN

   oCbx:oGet:bKeyChar = { | nKey | oCbx:GetKeyChar( nKey ) }

   ACTIVATE DIALOG oDlg CENTERED

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
horacio
Posts: 1270
Joined: Wed Jun 21, 2006 12:39 am
Location: Capital Federal Argentina

Re: editable combobox con busqueda incremental

Post by horacio »

Antonio, obtengo este error del ejemplo que posteaste

Code: Select all

Application
===========
   Path and name: C:\funciones\combo.exe (32 bits)
   Size: 1,684,992 bytes
   Compiler version: Harbour 3.1.0dev (Rev. 17222)
   FiveWin  Version: FWH 12.03
   Windows version: 6.1, Build 7601 Service Pack 1

   Time from start: 0 hours 0 mins 1 secs 
   Error occurred at: 09/26/14, 07:00:28
   Error description: Error BASE/1004  Message not found: TCOMBOBOX:GETKEYCHAR
   Args:
     [   1] = O   TCOMBOBOX

Stack Calls
===========
   Called from:  => __ERRRT_SBASE( 0 )
   Called from: ../../../tobject.prg => TCOMBOBOX:ERROR( 0 )
   Called from: ../../../tobject.prg => (b)HBOBJECT( 0 )
   Called from: ../../../tobject.prg => TCOMBOBOX:MSGNOTFOUND( 0 )
   Called from: ../../../tobject.prg => TCOMBOBOX:GETKEYCHAR( 0 )
   Called from: combo.prg => (b)MAIN( 13 )
   Called from: .\source\classes\TGET.PRG => TGET:KEYCHAR( 1028 )
   Called from:  => TWINDOW:HANDLEEVENT( 0 )
   Called from: .\source\classes\CONTROL.PRG => TCONTROL:HANDLEEVENT( 1700 )
   Called from: .\source\classes\TGET.PRG => TGET:HANDLEEVENT( 579 )
   Called from: .\source\classes\WINDOW.PRG => _FWH( 3153 )
   Called from:  => DIALOGBOXINDIRECT( 0 )
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:ACTIVATE( 270 )
   Called from: combo.prg => MAIN( 15 )
 
Saludos
User avatar
karinha
Posts: 4882
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: editable combobox con busqueda incremental

Post by karinha »

horacio wrote:Antonio, obtengo este error del ejemplo que posteaste

Code: Select all

Application
===========
   Path and name: C:\funciones\combo.exe (32 bits)
   Size: 1,684,992 bytes
   Compiler version: Harbour 3.1.0dev (Rev. 17222)
   FiveWin  Version: FWH 12.03
   Windows version: 6.1, Build 7601 Service Pack 1

   Time from start: 0 hours 0 mins 1 secs 
   Error occurred at: 09/26/14, 07:00:28
   Error description: Error BASE/1004  Message not found: TCOMBOBOX:GETKEYCHAR
   Args:
     [   1] = O   TCOMBOBOX

Stack Calls
===========
   Called from:  => __ERRRT_SBASE( 0 )
   Called from: ../../../tobject.prg => TCOMBOBOX:ERROR( 0 )
   Called from: ../../../tobject.prg => (b)HBOBJECT( 0 )
   Called from: ../../../tobject.prg => TCOMBOBOX:MSGNOTFOUND( 0 )
   Called from: ../../../tobject.prg => TCOMBOBOX:GETKEYCHAR( 0 )
   Called from: combo.prg => (b)MAIN( 13 )
   Called from: .\source\classes\TGET.PRG => TGET:KEYCHAR( 1028 )
   Called from:  => TWINDOW:HANDLEEVENT( 0 )
   Called from: .\source\classes\CONTROL.PRG => TCONTROL:HANDLEEVENT( 1700 )
   Called from: .\source\classes\TGET.PRG => TGET:HANDLEEVENT( 579 )
   Called from: .\source\classes\WINDOW.PRG => _FWH( 3153 )
   Called from:  => DIALOGBOXINDIRECT( 0 )
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:ACTIVATE( 270 )
   Called from: combo.prg => MAIN( 15 )
 
Saludos
Mira en COMBOBOX.PRG se tiens esto:

Code: Select all

METHOD GetKeyChar( nKey ) CLASS TComboBox

   local nAt, cText

   if ( nKey == VK_TAB .and. ! GetKeyState( VK_SHIFT ) ) .or. nKey == VK_RETURN
      ::oWnd:GoNextCtrl( ::hWnd )
      return 0
   else   
      if nKey == VK_TAB .and. GetKeyState( VK_SHIFT )
         ::oWnd:GoPrevCtrl( ::hWnd )
         return 0
      endif
   endif
   
   if nKey >= Asc( "a" ) .and. nKey >= Asc( "Z" )
      ::oGet:oGet:Insert( Chr( nKey ) )
      cText = AllTrim( ::oGet:oGet:buffer )
      if ( nAt := AScan( ::aItems, { | c | Upper( Left( c, Len( cText ) ) ) == ;
                                           Upper( cText ) } ) ) != 0
         MsgBeep()
         ::oGet:SetText( ::aItems[ nAt ] )
         ::oGet:SetPos( ::oGet:oGet:pos )
         return 0
      endif
   endif
   
return nKey          
 
Salu2
João Santos - São Paulo - Brasil
horacio
Posts: 1270
Joined: Wed Jun 21, 2006 12:39 am
Location: Capital Federal Argentina

Re: editable combobox con busqueda incremental

Post by horacio »

Karinha, efectivamente ese método no existe. Hay alguna manera de implementar la búsqueda sin este método ?? Gracias

Saludos
User avatar
karinha
Posts: 4882
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: editable combobox con busqueda incremental

Post by karinha »

horacio wrote:Karinha, efectivamente ese método no existe. Hay alguna manera de implementar la búsqueda sin este método ?? Gracias

Saludos

No. Necesita de una nueva COMBOBOX.PRG. ¿Dónde tiene nuevos métodos. ¿Por qué no actualizar su versión de FWH?

Pregunte al maestro Antonio un muy buen precio. No hay daño en el intento. jejejejejejejejeje

Abrazos.
João Santos - São Paulo - Brasil
User avatar
karinha
Posts: 4882
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: editable combobox con busqueda incremental

Post by karinha »

UNLIMITED ComboBox, Very good!

Code: Select all

#include "FiveWin.ch"

FUNCTION Test()

   LOCAL oDlg , oCombo1, oExit, oLeft, oRight, oFnt, oFont

   dbcreate("testdb.dbf",{{"feld1","C",10,0}})
   USE

   USE ("testdb.dbf") ALIAS "testdb" NEW EXCLUSIVE

   testdb->(dbappend())
   testdb->feld1 := replicate("A",len(testdb->feld1))
   testdb->(dbappend())
   testdb->feld1 := "ABCDEFGHIJ"
   testdb->(dbappend())
   testdb->feld1 := replicate("B",len(testdb->feld1))
   testdb->(dbgotop())

   SetGetColorFocus()

   SkinButtons()   // Show...

   DEFINE FONT oFnt   NAME "Ms Sans Serif" SIZE 0,  14 BOLD //UnderLine
   DEFINE FONT oFont  NAME "Ms Sans Serif" SIZE 0, -14 BOLD //UnderLine

   DEFINE DIALOG oDlg TITLE "Combobox CBS_DROPDOWN Search In..." ;
          FROM 0,0 TO 304, 350 PIXEL COLORS CLR_BLACK, CLR_WHITE TRANSPARENT

   oDlg:lHelpIcon := .F.

   @ 1,2 SAY "Recno: "+alltrim(str(testdb->(recno()))) UPDATE

   @ 2, 2 COMBOBOX oCombo1 VAR testdb->feld1                               ;
          PROMPTS { replicate("A",len(testdb->feld1)),                     ;
                    replicate("B",len(testdb->feld1))} OF oDlg SIZE 80, 80 ;
                    STYLE CBS_DROPDOWN UPDATE

   oCombo1:oGet:bKeyChar = { | nKey | oCombo1:GetKeyChar( nKey ) } // Wow...

   @ 3,2 SAY "Type a letter for search... God save the king." UPDATE ;
         COLORS CLR_HRED, CLR_WHITE

   @ 4, 8 BUTTON oLeft PROMPT "&Left" OF oDlg ;
          ACTION if( testdb->(recno())>1,(testdb->(dbskip(-1) ), ;
                     oDlg:update()),msginfo("Begin of DB") )

   oLeft:cToolTip := "Use Left For Incremental Search"

   @ 4, 17 BUTTON oRight PROMPT "&Right" OF oDlg ;
           ACTION if( testdb->(recno())<3,(testdb->(dbskip(1)),  ;
                      oDlg:update()),msginfo("End of DB") )

   oRight:cToolTip := "Use Right For Incremental Search"

   @ 6,1 SAY "1. Go with > to the second record."+CRLF+ ;
             "2. Go with > to the third record"+CRLF+   ;
             "3. Go with < return to the second record"+CRLF+ ;
             "4. Open the Combobox with the arrow"+CRLF+CRLF+;
             "Now you see, that the second record also is 'AAAAAAAAAA'" ;
             SIZE 200,50

   @ 7.50, 12 BUTTON oExit PROMPT "&Exit"  OF oDlg ;
              ACTION ( oDlg:End() ) CANCEL UPDATE

   oExit:cToolTip := "Exit"

   SET FONT OF oLeft  TO oFont
   SET FONT OF oRight TO oFont
   SET FONT OF oExit  TO oFont

   ACTIVATE DIALOG oDlg CENTERED

   oFnt:End()
   oFont:End()

   USE

RETURN NIL
 
João Santos - São Paulo - Brasil
Post Reply