Searching on Xbrowse with array

Searching on Xbrowse with array

Postby Silvio.Falconi » Sun Nov 08, 2020 9:08 pm

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  Expand view

#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.
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7033
Joined: Thu Oct 18, 2012 7:17 pm

Re: Searching on Xbrowse

Postby leandro » Mon Nov 09, 2020 3:05 pm

Silvio buenos días,

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

http://forums.fivetechsupport.com/viewtopic.php?f=6&t=38318&p=228821&hilit=xbrowse+incremental+array#p228821
Saludos
LEANDRO AREVALO
Bogotá (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Embarcadero C++ 7.60 for Win32 ] [ FiveWin 23.07 ] [ xHarbour 1.3.0 Intl. (SimpLex) (Build 20230914) ]
User avatar
leandro
 
Posts: 1669
Joined: Wed Oct 26, 2005 2:49 pm
Location: Colombia

Re: Searching on Xbrowse

Postby Silvio.Falconi » Mon Nov 09, 2020 10:10 pm

leandro wrote:Silvio buenos días,

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

http://forums.fivetechsupport.com/viewtopic.php?f=6&t=38318&p=228821&hilit=xbrowse+incremental+array#p228821

I allready saw it
1) I not wish lgetbar ( not like it to my customer )
2) I search something for an array
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7033
Joined: Thu Oct 18, 2012 7:17 pm

Re: Searching on Xbrowse

Postby Silvio.Falconi » Tue Nov 10, 2020 10:42 am

leandro wrote:Silvio buenos días,

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

http://forums.fivetechsupport.com/viewtopic.php?f=6&t=38318&p=228821&hilit=xbrowse+incremental+array#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!!!!
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7033
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 16 guests