// Using a TreeView with checkboxes and checking their status
#include "FiveWin.ch"
function Main()
local oDlg, oTree
DEFINE DIALOG oDlg
oTree = TTreeView():New( 0, 0, oDlg,,,,,200,200,,.t.)
oTree:OnClick = { | nRow, nCol | CheckStatus( oTree, oTree:aItems, nRow, nCol ) }
ACTIVATE DIALOG oDlg CENTERED ON INIT BuildTree( oTree )
return nil
function BuildTree( oTree )
local oMenu := Array( 2 ), oSubMenu := Array( 3 )
oMenu[ 1 ]:= oTree:Add( "Principal" )
oMenu[ 1 ]:Cargo = "01"
oSubMenu[ 1 ]:= oMenu[ 1 ]:Add( "Imprimir..." )
oSubMenu[ 1 ]:SetCheck( .T. )
oSubMenu[ 1 ]:Cargo = "01:01"
oMenu[ 2 ]:= oTree:Add( "Proyectos" )
oMenu[ 2 ]:Cargo = "02"
oSubMenu[ 2 ]:= oMenu[ 2 ]:Add( "Definir Proyectos" )
oSubMenu[ 2 ]:Cargo = "02:01"
oSubmenu[ 3 ]:= oMenu[ 2 ]:Add( "Actualización datos" )
oSubMenu[ 3 ]:Cargo = "02:02"
oTree:Expand()
return nil
function CheckStatus( oTree, aItems, nRow, nCol )
local n, lActivo, nn, x
local cPrompt, cCargo
local oItem
local aiTmp
oItem := oTree:HitTest( nRow, nCol )
nn := LEN(oItem:cargo)
lActivo:= oTree:GetCheck( oItem )
for n = 1 to Len( aItems )
if LEFT(aItems[ n ]:cargo,nn) == oItem:cargo
aiTmp:= aItems[n]:aItems
FOR x:= 1 TO LEN( aiTmp )
oTree:SetCheck( aiTmp[ x ], lActivo )
NEXT
endif
next
return nil
acuellar wrote:Daniel,
En el ejemplo posteado da error cuando se da click en menos (-)
El error es:
'NIL' has no exported method: CARGO
Saludos,
Adhemar
Ariel wrote:Bueno,
yo encontre el siguiente tema y tambien la solucion, pero no sé como implementarla.
si tenemos una estructura
menu1
submenu1
submenu2
menu2
-.-
ahi anda ok
ahora si tenemos :
menu1
submenu1
submenu1.1
submenu1.2
submenu2
menu2
da error cuando pulso el +, el mismo q plantea jose, con la var CARGO, y entiendo q oItem va a NIL, x eso da error.
Lo q entiendo es q en el ejemplo q puso Daniel, y q habiamos empezado a probar con jose, es q faltaria como una recursividad para subopciones, pero no se como implementar eso...
bueno, a ver los experimentados si nos echan una manito.
Gracias., salu2.
// Using a TreeView with checkboxes and checking their status
#include "FiveWin.ch"
function Main()
local oDlg, oTree
DEFINE DIALOG oDlg SIZE 400, 600
oTree = TTreeView():New( 0, 0, oDlg,,,,,200,300,,.t.)
oTree:OnClick = { | nRow, nCol | CheckStatus( oTree, oTree:aItems, nRow, nCol ) }
ACTIVATE DIALOG oDlg CENTERED ON INIT BuildTree( oTree )
return nil
function BuildTree( oTree )
local oMenu
local oSub, oSub2, oSub3
oMenu := oTree:Add( "menu 1" )
oSub = oMenu:Add( "submenu 1" )
oSub = oMenu:Add( "submenu 2" )
oSub = oMenu:Add( "submenu 3" )
oSub = oMenu:Add( "submenu 4" )
oSub = oMenu:Add( "submenu 5" )
oSub2 = oSub:Add( "submenu 5-1" )
oSub2 = oSub:Add( "submenu 5-2" )
oSub2 = oSub:Add( "submenu 5-3" )
oSub2 = oSub:Add( "submenu 5-4" )
oSub2 = oSub:Add( "submenu 5-5" )
oSub = oSub2:Add( "submenu 5-5-1" )
oSub = oSub2:Add( "submenu 5-5-2" )
oSub = oSub2:Add( "submenu 5-5-3" )
oSub = oSub2:Add( "submenu 5-5-4" )
oSub2 = oSub:Add( "submenu 5-5-1-1" )
oSub2 = oSub:Add( "submenu 5-5-1-2" )
oSub2 = oSub:Add( "submenu 5-5-1-3" )
oMenu := oTree:Add( "Principal" )
oSub = oMenu:Add( "Imprimir..." )
oTree:Expand()
return nil
function CheckStatus( oTree, aItems, nRow, nCol )
local lActivo
local oItem
oItem := oTree:HitTest( nRow, nCol )
if oItem != NIL
lActivo:= oTree:GetCheck( oItem )
RunItems( oItem:aItems, lActivo )
endif
return nil
//----------------------------------------------------------------------------//
function RunItems( aItems, lActivo )
local n, oItem
for n = 1 to Len( aItems )
aItems[ n ]:SetCheck( lActivo )
if Len( aItems[ n ]:aItems ) > 0
RunItems( aItems[ n ]:aItems, lActivo )
endif
next
return nil
// Using a TreeView with checkboxes and checking their status
#include "FiveWin.ch"
function Main()
local oDlg, oTree
DEFINE DIALOG oDlg SIZE 400, 600
oTree = TTreeView():New( 0, 0, oDlg,,,,,200,300,,.t.)
oTree:OnClick = { | nRow, nCol | CheckStatus( oTree, oTree:aItems, nRow, nCol ) }
ACTIVATE DIALOG oDlg CENTERED ON INIT BuildTree( oTree )
return nil
function BuildTree( oTree )
local oMenu
local oSub, oSub2, oSub3
oMenu := oTree:Add( "menu 1" )
oSub = oMenu:Add( "submenu 1" )
oSub:SetCheck( .t. )
oSub = oMenu:Add( "submenu 2" )
oSub = oMenu:Add( "submenu 3" )
oSub = oMenu:Add( "submenu 4" )
oSub = oMenu:Add( "submenu 5" )
oSub2 = oSub:Add( "submenu 5-1" )
oSub2 = oSub:Add( "submenu 5-2" )
oSub2:SetCheck( .t. )
oSub2 = oSub:Add( "submenu 5-3" )
oSub2 = oSub:Add( "submenu 5-4" )
oSub2 = oSub:Add( "submenu 5-5" )
oSub = oSub2:Add( "submenu 5-5-1" )
oSub = oSub2:Add( "submenu 5-5-2" )
oSub:SetCheck( .t. )
oSub = oSub2:Add( "submenu 5-5-3" )
oSub = oSub2:Add( "submenu 5-5-4" )
oSub2 = oSub:Add( "submenu 5-5-1-1" )
oSub2 = oSub:Add( "submenu 5-5-1-2" )
oSub2:SetCheck( .t. )
oSub2 = oSub:Add( "submenu 5-5-1-3" )
oMenu := oTree:Add( "Principal" )
oSub = oMenu:Add( "Imprimir..." )
oTree:Expand()
return nil
function CheckStatus( oTree, aItems, nRow, nCol )
local lActivo
local oItem
oItem := oTree:HitTest( nRow, nCol )
if oItem != NIL
lActivo:= oTree:GetCheck( oItem )
RunItems( oItem:aItems, lActivo )
endif
return nil
//----------------------------------------------------------------------------//
function RunItems( aItems, lActivo )
local n, oItem
for n = 1 to Len( aItems )
aItems[ n ]:SetCheck( lActivo )
if Len( aItems[ n ]:aItems ) > 0
RunItems( aItems[ n ]:aItems, lActivo )
endif
next
return nil
// Using a TreeView with checkboxes and checking their status
#include "FiveWin.ch"
function Main()
local oWnd
local oMenu
MENU oMenu
MENUITEM "Tree 1" ACTION treeuno()
MENUITEM "Tree 2" ACTION treedos()
ENDMENU
define window oWnd menu oMenu
activate window oWnd
return nil
function treeuno()
local oTree, oDlg
DEFINE DIALOG oDlg SIZE 400, 600
oTree = TTreeView():New( 0, 0, oDlg,,,,,200,300,,.t.)
oTree:OnClick = { | nRow, nCol | CheckStatus( oTree, oTree:aItems, nRow, nCol ) }
ACTIVATE DIALOG oDlg CENTERED ON INIT ( BuildTree( oTree ) ) NOWAIT
SetInitItem( oTree )
return nil
function treedos()
local oTree, oDlg
DEFINE DIALOG oDlg SIZE 400, 600
oTree = TTreeView():New( 0, 0, oDlg,,,,,200,300,,.t.)
oTree:OnClick = { | nRow, nCol | CheckStatus( oTree, oTree:aItems, nRow, nCol ) }
oDlg:bPainted = {|| SetInitItem( oTree ) }
ACTIVATE DIALOG oDlg CENTERED ON INIT ( BuildTree( oTree ) )
return nil
function SetInitItem( oTree )
if oTree:Cargo == NIL
SysRefresh()
oTree:aItems[ 1 ]:aItems[ 1 ]:SetCheck( .T. )
oTree:aItems[ 1 ]:aItems[ 5 ]:aItems[ 2 ]:SetCheck( .T. )
oTree:aItems[ 1 ]:aItems[ 5 ]:aItems[ 5 ]:aItems[ 2 ]:SetCheck( .T. )
oTree:aItems[ 1 ]:aItems[ 5 ]:aItems[ 5 ]:aItems[ 4 ]:aItems[ 2 ]:SetCheck( .T. )
oTree:Cargo = 1
endif
return nil
function BuildTree( oTree )
local oMenu
local oSub, oSub2, oSub3
oMenu := oTree:Add( "menu 1" )
oSub = oMenu:Add( "submenu 1" )
// oSub:SetCheck( .t. )
oSub = oMenu:Add( "submenu 2" )
oSub = oMenu:Add( "submenu 3" )
oSub = oMenu:Add( "submenu 4" )
oSub = oMenu:Add( "submenu 5" )
oSub2 = oSub:Add( "submenu 5-1" )
oSub2 = oSub:Add( "submenu 5-2" )
// oSub2:SetCheck( .t. )
oSub2 = oSub:Add( "submenu 5-3" )
oSub2 = oSub:Add( "submenu 5-4" )
oSub2 = oSub:Add( "submenu 5-5" )
oSub = oSub2:Add( "submenu 5-5-1" )
oSub = oSub2:Add( "submenu 5-5-2" )
// oSub:SetCheck( .t. )
oSub = oSub2:Add( "submenu 5-5-3" )
oSub = oSub2:Add( "submenu 5-5-4" )
oSub2 = oSub:Add( "submenu 5-5-1-1" )
oSub2 = oSub:Add( "submenu 5-5-1-2" )
// oSub2:SetCheck( .t. )
oSub2 = oSub:Add( "submenu 5-5-1-3" )
oMenu := oTree:Add( "Principal" )
oSub = oMenu:Add( "Imprimir..." )
oTree:ExpandAll()
return nil
function CheckStatus( oTree, aItems, nRow, nCol )
local lActivo
local oItem
oItem := oTree:HitTest( nRow, nCol )
if oItem != NIL
lActivo:= oTree:GetCheck( oItem )
RunItems( oItem:aItems, lActivo )
endif
return nil
//----------------------------------------------------------------------------//
function RunItems( aItems, lActivo )
local n, oItem
for n = 1 to Len( aItems )
aItems[ n ]:SetCheck( lActivo )
if Len( aItems[ n ]:aItems ) > 0
RunItems( aItems[ n ]:aItems, lActivo )
endif
next
return nil
#Include "FiveWin.ch"
Static aSelected := {}
Static oTree
//----------------------------------------------------------------------------//
Function Main()
local oDlg, oImageList
local oBtt1
local oBtt2
local oBtt3
local oFnt
DEFINE FONT oFnt NAME "Calibri" SIZE 0, -16
DEFINE DIALOG oDlg TITLE "Tipos de Servicios" SIZE 600, 650 FONT oFnt
oDlg:lHelpIcon := .F.
@ 07, 05 BTNBMP oBtt1 PROMPT "Seleccionados" FILENAME "..\bitmaps\link.bmp" OF oDlg ;
ACTION ( if( Empty( oImageList ), NewSelected( oTree:aItems ), Selected( oTree:aItems ) ), ;
XBrowse( aSelected ) ) SIZE 80, 32 LEFT ;
COLOR CLR_WHITE, Rgb( 160, 160, 160 ) ;
FLAT PIXEL NOROUND NOBORDER // TRANSPARENT
@ ( oDlg:nHeight / 2 ) - 40, 05 BTNBMP oBtt2 PROMPT "Salir" FILENAME "..\bitmaps\exit.bmp" OF oDlg ;
ACTION ( oDlg:End() ) SIZE 80, 32 RIGHT ;
COLOR CLR_WHITE, Rgb( 160, 160, 160 ) ;
FLAT PIXEL NOROUND NOBORDER // TRANSPARENT
oImageList := TImageList():New( 16, 16 )
oImageList:Add( TBitmap():Define( "conex_off1",, oDlg ) , TBitmap():Define( "conex_off",, oDlg ) )
oImageList:Add( TBitmap():Define( "conex_on1",, oDlg ) , TBitmap():Define( "conex_on",, oDlg ) )
oImageList:Add( TBitmap():Define( "conex_work",, oDlg ), TBitmap():Define( "conex_fet",, oDlg ) )
@ 0.5, 15 TREEVIEW oTree OF oDlg SIZE 205, 310 COLOR Rgb( 128, 128, 128 ), GetSysColor( 5 ) //CHECK
oTree:nStyle += WS_BORDER
oTree:bLClicked := { | nRow, nCol, nKeyFlags | if( Empty( oImageList ), ;
NewClick( nRow, nCol ), ;
MyClick( nRow, nCol ) ) }
ACTIVATE DIALOG oDlg CENTERED ON INIT ( NewAddItems( oImageList ), oTree:Expand() )
RELEASE FONT oFnt
Return NIL
//----------------------------------------------------------------------------//
Function NewAddItems( oImageList, nImg1, nImg2 )
local x
local y
local oItem
local oItem1
local aItems := { "LAVADOS", "NEUMATICOS", "ALINEACION", "CAMBIO DE ACEITE", ;
"FILTROS", "ENGRASE", "SERVICIOS VARIOS" }
local aSubItems := { { "INTERIOR", "EXTERIOR", "MOTOR", "CHASIS", "PULVERIZADO" }, ;
{ "MONTAJE", "BALANCEO", "ARREGLO" }, ;
{ "REVISION ALINEACION", "ALINEACION" }, ;
{ "MOTOR", "CAJA", "DIFERENCIAL" }, ;
{ "ACEITE", "CARBURANTE", "CAJA CAMBIOS", "AIRE", "HABITACULO" }, ;
{ "ENGRASE" }, ;
{ "MECANICA", "ELECTRICO" } }
if !Empty( oImageList )
oTree:SetImageList( oImageList )
DEFAULT nImg1 := 0
DEFAULT nImg2 := 0
else
DEFAULT nImg1 := 0
DEFAULT nImg2 := 0
endif
For x = 1 to Len( aItems )
oItem := oTree:Add( " " + aItems[ x ], nImg1 )
For y = 1 to Len( aSubItems[ x ] )
oItem1 := oItem:Add( " " + StrCapFirst( aSubItems[ x ][ y ] ), nImg2 )
oItem1:Cargo := aSubItems[ x ][ y ]
Next y
Next x
Return nil
//----------------------------------------------------------------------------//
Function MyClick( nRow, nCol, lInv )
local oItem
local nImg
DEFAULT lInv := .T.
oItem := oTree:HitTest( nRow, nCol )
if !hb_IsNil( oItem )
nImg := if( oItem:nImage = 0, 1, 0 )
oItem:Set( , nImg )
oItem:nImage := nImg
if hb_IsNil( oItem:Cargo )
if Len( oItem:aItems ) > 0
if lInv
AEVal( oItem:aItems, ;
{ | o | if( o:nImage = 1, ( o:Set( , 0 ), o:nImage := 0 ), ;
( o:Set( , 1 ), o:nImage := 1 ) ) } )
else
AEVal( oItem:aItems, ;
{ | o | o:Set( , oItem:nImage ), o:nImage := oItem:nImage } )
endif
endif
endif
endif
return nil
//----------------------------------------------------------------------------//
Function Selected( aItems )
local x
For x = 1 to Len( aItems )
oItem := aItems[ x ]
if Len( oItem:aItems ) == 0
if oItem:nImage == 1
AAdd( aSelected, { oItem:cPrompt, oItem:nImage } )
endif
else
Selected( oItem:aItems )
endif
Next x
Return nil
//----------------------------------------------------------------------------//
Function NewClick( nRow, nCol )
local oItem
oItem := oTree:HitTest( nRow, nCol )
if !Empty( oItem )
if Len( oItem:aItems ) > 0
AEVal( oItem:aItems, { | o | oTree:SetCheck( o, !oTree:GetCheck( o ) ) } )
endif
endif
Return nil
//----------------------------------------------------------------------------//
Function NewSelected( aItems )
local x
For x = 1 to Len( aItems )
oItem := aItems[ x ]
if Len( oItem:aItems ) == 0
if oTree:GetCheck( oItem )
AAdd( aSelected, LTrim( oItem:cPrompt ) )
endif
else
NewSelected( oItem:aItems )
endif
Next x
Return nil
//----------------------------------------------------------------------------//
Return to FiveWin para Harbour/xHarbour
Users browsing this forum: No registered users and 57 guests