grouping the customer.dbf archive into groups for a sample (married, age >50) making the user select the desired group and then go back to normal xbrowse
obviously with search on the fields depending on the indexes
thanks for a solution
a small test
- Code: Select all Expand view RUN
#include "fivewin.ch"
REQUEST DBFCDX
static lTipo1:=.f.,ltipo2:=.f.
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
function Main()
local oDlg, oBrw, oGroup
local oSay:=array(2)
local cSeek:=Space(100)
local oGet
local oDbf,aCols
oDbf:=Tdatabase():Open( , "Customer", "DBFCDX", .T. )
oDbf:SetOrder("FIRST")
oDbf:Gotop()
aCols := { ;
{ "FIRST" , "Cognome" ,, 140, },;
{ "LAST" , "Nome" ,, 150, },;
{ "STREET" , "Indirizzo" ,, 150, },;
{ "CITY" , "Città" ,, 150, },;
{ "STATE" , "Stato" ,, 150, },;
{ "ZIP" , "Cap" ,, 150, },;
{ "HIREDATE" , "Assunzione" ,, 150, },;
{ "MARRIED" , "Sposato" ,, 150, },;
{ "AGE" , "Età" ,, 150, },;
{ "SALARY" , "Stipendio" ,, 150, },;
{ "NOTES" , "Appunti" ,, 150, }}
DEFINE DIALOG oDlg SIZE 800,400 PIXEL TRUEPIXEL RESIZABLE
@ 12,15 say oSay[1] Prompt "Search" SIZE 46,24 PIXEL OF oDlg TRANSPARENT
@ 12,450 say oSay[2] Prompt "in" SIZE 20,24 PIXEL OF oDlg TRANSPARENT
@ 10, 165 GET oGet VAR cSeek SIZE 200,19 PIXEL OF oDlg PICTURE "@!"
/* @ nRow - 1, 10 COMBOBOX nFilter SIZE 60, If( IsAppThemed(), 14, 60 ) PIXEL OF oDlg ;
ITEMS { "Search For", "Show Only" } ;
ON CHANGE ( oBrw:Seek( "" ), oBrw:lIncrFilter := nFilter > 1, oBrw:SetFocus() )
@ nRow - 1, 72 COMBOBOX nSeekWild ;
size 60, If( IsAppThemed(), 14, 60 ) pixel of oDlg ;
ITEMS { "Starting With", "Containing" } ;
on change ( oBrw:lSeekWild := ( nSeekWild > 1 ), oBrw:Seek( "" ), oBrw:SetFocus() )
*/
@ 10, 700 BTNBMP oGroup Prompt "group on" ;
FLAT SIZE 80, 20 OF oDlg PIXEL ;
BITMAP ".\bitmaps\combo.bmp" RIGHT NOROUND;
ACTION ::ShowPopUp( { |oBtn| BtnPop( oDbf,oDlg, oBrw,aCols,oGet ) } )
ACTIVATE DIALOG oDlg CENTERED;
on init oBrw:= MyBrowse(oDbf,oDlg, oBrw,aCols,oGet)
return nil
//--------------------------------------------------------------------------------//
Function MyBrowse(oDbf,oDlg, oBrw,aCols,oGet)
@ 80,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
DATASOURCE oDbf COLUMNS aCols ;
AUTOSORT ;
NOBORDER CELL LINES
WITH OBJECT oBrw
:lHScroll := .f.
:SetMultiSelectCol()
//---
:lIncrFilter := .t.
:bOnSort := { |b,oCol| oBrw:Seek( "" ), ;
oBrw:cFilterFld := oCol:cExpr, ;
oBrw:SetFocus() }
:oSeek := oGet
//----
:CreateFromCode()
END
@ 10, 550 COMBOBOX oBrw:oSortCbx VAR oBrw:cSortOrder;
SIZE 100,400 PIXEL OF oDlg HEIGHTGET 14.8 STYLE CBS_DROPDOWN
return oBrw
//--------------------------------------------------------------------------------//
Function BtnPop(oDbf,oDlg, oBrw,aCols,oGet)
local oItem1,oItem2
MENU oMenu POPUP
MENUITEM oItem1 PROMPT "State" ;
ACTION (lTipo1 := !lTipo1,;
( Iif( ltipo1,MakeGroup(oDbf,oDlg, oBrw,aCols,oGet),;
MyBrowse(oDbf,oDlg, oBrw,aCols,oGet) )))
oItem1:SetCheck(lTipo1)
ENDMENU
return oMenu
//---------------------------------------------------------------------//
Function MakeGroup(oDbf,oDlg, oBrw,aCols,oGet) // simulation
local aDatatree:={}
local aState:={}
local cState :=""
local n:= 1
local k
local aHeaders:= { "First","Last","City","State"}
local oCol
//load State
Do while .not. oDbf:eof()
IF !Empty(oDbf:state) .and. oDbf:State!=cState
aadd(aState,oDbf:State)
n++
Endif
cState:= oDbf:State
oDbf:skip()
Enddo
oDbf:gotop()
oBrw:ResetData( nil,{} )
// see on dbf for state
k:= 0
For n= 1 to len( astate)
k:=k+1
aadd(aDatatree,{"State"+chr(187)+aState[n] ,"","","",k } )
oDbf:Seek(aState[n])
Do while !oDbf:Eof()
if alltrim(oDbf:state) == alltrim(astate[n])
k:=k+1
aadd(aDatatree,{space(20)+alltrim(oDbf:First),oDbf:Last,oDbf:city,oDbf:state,k } )
else
exit
Endif
oDbf:skip()
enddo
oDbf:gotop()
Next
oDbf:close()
// make a sort
aDatatree := aSort( aDatatree,,,{|x,y| (x[5]) < (y[5])})
// insert on xbrowse
oBrw:ResetData( nil,{} )
oBrw:lAutoSort := .t.
oBrw:setarray(aDatatree)
// set the titles
oBrw:aCols[ 1 ]:cHeader := "State"
oBrw:aCols[ 2 ]:cHeader := "First"
oBrw:aCols[ 3 ]:cHeader := "Last"
oBrw:aCols[ 4 ]:cHeader := "Last"
oBrw:aCols[ 5 ]:cHeader := "State"
// hide :aCols[5] the number I used
oBrw:aCols[5]:Hide()
//these not run
oBrw:lIncrFilter := .t.
oBrw:lSeekWild := .t.
oBrw:bOnSort := { |b,oCol| oBrw:Seek( "" ), ;
oBrw:cFilterFld := oCol:cExpr, ;
oBrw:SetFocus() }
oBrw:oSeek := oGet
// refresh()
oBrw:refresh()
return nil
//-------------------------------------------------------------------------------------------------------------//