Searching on Xbrowse with array

Post Reply
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Searching on Xbrowse with array

Post by Silvio.Falconi »

in an old dialog I easily search for customers (using a Dbf) by entering even a few letters in a get and selecting in the combo which field I want to search, the procedure uses IncrFilter and everything works fine.


Image


I made it with a get and th epossibility to select the column where search
So if I must search a City init with "Orz" I select the city column

Image


On Dbf it seem be more easy than on array

Now I'd like to try searching an array in the same way except I don't understand how to do it

Could anyone help me figure out how to do it?

I tried to make a test but make me error on function xSetFilter( oBrw ) and method oBrw:ArrayIncrFilter

Image

I wish have a get and the combobox to select column where search
and I need to have a first column with the possibility to check it

Code: Select all

 
#include "fivewin.ch"
 #include "constant.ch"

REQUEST DBFCDX


static cSeek   := ''
static oSeek



Function MAin()
local aData  :=  {}
local afield :=  { "FIRST","LAST","STREET","CITY","STATE"}
local aTxt   :=  { "Cognome","Nome","Indirizzo","Città","Provincia"}
local nField := 1

       USE CUSTOMER
       aData := FW_DbfToArray( "FIRST,LAST,STREET,CITY,STATE" )
       CLOSE CUSTOMER

Tabella(adata,afield,aTxt,nField)

RETURN NIL

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

Function Tabella(adata,afield,aTxt,nField)
   local  oTabella,oLbx,oFontDialog,oBrw,oFontDialog2
   local  nBottom   := 30
   local  nRight    := 99.9
   local  nWidth    :=  Max( nRight * DLG_CHARPIX_W, 180 )
   local  nHeight   := nBottom * DLG_CHARPIX_H
   local  aBtnBrow  := array(4)
   local  oCursorBtn :=TCursor():New(,'HAND')
   local  cSearch:=space(20)
   local aGet[2]


      DEFINE FONT oFontDialog NAME 'Tahoma' SIZE 0, -16
      DEFINE FONT oFontDialog2 NAME 'Tahoma' SIZE 0, -14
      DEFINE DIALOG oTabella  SIZE nWidth, nHeight TRANSPARENT ;
      TITLE "Searching on customer" COLOR CLR_BLACK,  nRgb( 245,244,234) FONT oFontDialog;
      STYLE nOr( DS_MODALFRAME, WS_POPUP, WS_CAPTION,  4 )


   @ 30, 05 XBROWSE oBrw SIZE 385,160 PIXEL OF oTabella ;
      DATASOURCE aData AUTOCOLS;   //COLUMNS { || .F. }, "FIRST","LAST","STREET","CITY","STATE" ;
      HEADERS "Cognome","Nome","Indirizzo","Città", "State" ;
      CELL LINES NOBORDER  FOOTERS






      ADD COLUMN TO XBROWSE oBrw   AT 1 // add a column for checkbox

    FOR i := 1 TO LEN(oBrw:aCols)
      oCol := oBrw:aCols[ i ]
      oCol:bClrSelFocus  := { || { CLR_BLACK, nRGB(202,224,252) } }
    NEXT



 WITH OBJECT oBrw
   :l2007:=.f.
   :lColDividerComplete := .t.
   :lRecordSelector     := .t.
   :lHScroll            := .f.
   :nHeaderHeight       := 30
   :nRowHeight          := 30
   :nStretchCol         := -1
   :lDrawBorder := .t.
   :CreateFromCode()
  END



     @ 12,  11 SAY "Search:"     SIZE  55,   12 PIXEL  OF  oTabella  COLOR 0, 14215660
     @ 10,  45  GET aGet[1] VAR cSearch  SIZE  130,  14  PIXEL OF oTabella;
      ON CHANGE  (cSeek:=AllTrim( cSearch )   )    UPDATE

     @ 12,  181 SAY "in"     SIZE  55,   12 PIXEL  OF  oTabella  COLOR 0, 14215660
     @ 10,  195 COMBOBOX aGet[2] var nField ITEMS aTxt  SIZE  130, 90  PIXEL OF oTabella HEIGHTGET 22  UPDATE

      aGet[1]:bKeyDown := { | nKey | KeyChar( oBrw, nKey,nField,oBrw:aArrayData,afield[nField],aGet, cSeek) }

@ 10, 350  BTNBMP PROMPT "C" SIZE 15, 14 PIXEL OF oTabella FLAT ;
          ACTION ( oBrw:Seek( "" ), oBrw:SetFocus() )

 oBrw:bSeek  := nil
    ACTIVATE DIALOG oTabella CENTER

RETURN NIL



 static function KeyChar( oBrw, nKey,n,cdbf,cField,aGet,cSeek)


  If nKey == VK_BACK .and. ! Empty( cSeek )

     xSetFilter( oBrw, cSeek + Chr( nKey ),n,cField ,aget)

      return 0
   elseIf nKey > 31
      xSetFilter( oBrw, cSeek + Chr( nKey ),n,cField,aGet )

      return 0
   Endif

   return nil


  function xSetFilter( oBrw, cpattern,n,cField,aGet )

       local cFilter  := ""
       local oCol, c
       local cField_name :=alltrim(cField)
       local nCol  := n // column select with combobox


       if !Empty( cpattern )
          c  := Upper( AllTrim( cpattern ) )
          c  := "'" + c + "' $ Upper( cValToChar( aRow[" + LTrim( Str( nCol ) ) + "] ) )"
          cFilter  += c
        endif

        

       if Empty( cFilter )
          xClearFilter( oBrw,aGet )
       else
          cFilter  := "{ |c,aRow,oBrw| " + cFilter + " }"
          oBrw:bFilterExp  := &( cFilter )
          oBrw:ArrayIncrFilter( "dummy" )
          oBrw:Refresh()
          oBrw:SetFocus()
       endif

    return .t.


  function xClearFilter( oBrw,aGet )

        aget[1]:cText := Space(20)

       if oBrw:nLen < Len( oBrw:aArrayData )
          oBrw:bKeyCount    := { || Len( oBrw:aArrayData ) }
          oBrw:Refresh()
       endif
       oBrw:SetFocus()

    return .t.
 
Last edited by Silvio.Falconi on Tue Nov 10, 2020 9:14 am, edited 1 time in total.
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
User avatar
leandro
Posts: 958
Joined: Wed Oct 26, 2005 2:49 pm
Location: Colombia
Contact:

Re: Searching on Xbrowse

Post by leandro »

Silvio buenos días,

Encontré esto en el foro, creo que es lo que necesitas.

http://forums.fivetechsupport.com/viewt ... ay#p228821
Saludos
LEANDRO ALFONSO
SISTEMAS LYMA - BASE
Bogotá (Colombia)
[ FWH 19.09 ] [ xHarbour 1.2.3 Intl. (SimpLex) (Build 20190613) ] [ Embarcadero C++ 7.30 for Win32 ]
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Re: Searching on Xbrowse

Post by Silvio.Falconi »

leandro wrote:Silvio buenos días,

Encontré esto en el foro, creo que es lo que necesitas.

http://forums.fivetechsupport.com/viewt ... ay#p228821
I allready saw it
1) I not wish lgetbar ( not like it to my customer )
2) I search something for an array
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Re: Searching on Xbrowse

Post by Silvio.Falconi »

leandro wrote:Silvio buenos días,

Encontré esto en el foro, creo que es lo que necesitas.

http://forums.fivetechsupport.com/viewt ... ay#p228821
leandro
the Nages sample test xbgetbar.prg run ok

When you change the dbf and you wish use only some fields and you wish translate on your language the headers of fields
NOT RUN !!!!! Making errors!!!!
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
Post Reply