#include "fivewin.ch"
REQUEST DBFCDX
static lTipo1:=.f.,ltipo2:=.f.
//----------------------------------------------------------------------------//
function Main()
local aData
FERASE( "CUSTOMER.CDX" )
USE CUSTOMER NEW EXCLUSIVE VIA "DBFCDX"
aData := FW_DbfToArray( "FIRST,LAST,STREET,STATE", , { || RECNO() < 11 } )
GO TOP
FW_CdxCreate()
CLOSE CUSTOMER
Customers(aData)
return nil
//----------------------------------------------------------------------------//
function Customers(aData)
local oDlg, oBrw, oGroup
local oSay:=array(2)
local cSeek:=Space(100)
local oGet
DEFINE DIALOG oDlg SIZE 800,400 PIXEL TRUEPIXEL RESIZABLE
@ 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( aData, oDlg, oBrw,oGet ) } )
ACTIVATE DIALOG oDlg CENTERED;
on init oBrw:= MyBrowse(aData,oDlg, oBrw)
return nil
//--------------------------------------------------------------------------------//
Function MyBrowse(aData,oDlg, oBrw, oGet)
@ 60,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
DATASOURCE aData ;
AUTOCOLS ;
HEADERS "NAME","SURNAME","ADDRESS","STATE" ;
AUTOSORT ;
NOBORDER 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,20 COMBOBOX oBrw:oSortCbx VAR oBrw:cSortOrder SIZE 100,400 PIXEL OF oDlg
return oBrw
//--------------------------------------------------------------------------------//
Function BtnPop(aData, oDlg, oBrw,oGet)
local oItem1,oItem2
MENU oMenu POPUP
MENUITEM oItem1 PROMPT "State" ;
ACTION (lTipo1 := !lTipo1,;
( Iif( ltipo1,MakeGroup(oBrw,oGet,oDlg),;
MyBrowse(aData,oDlg, oBrw,oGet) )))
oItem1:SetCheck(lTipo1)
ENDMENU
return oMenu
//---------------------------------------------------------------------//
Function MakeGroup(oBrw,oGet,oDlg) // simulation
local aDatatree:={}
local aState:={}
local cState :=""
local n:= 1
local k
local aHeaders:= { "First","Last","City","State"}
local oCol
local oDbf
oDbf:=Tdatabase():Open(,"customer" ,"DBFCDX", .t.)
oDbf:setorder("state")
oDbf:gotop()
//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()
// 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
//-------------------------------------------------------------------------------------------------------------//