FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to know which item was checked on tree?
Posts: 22
Joined: Mon May 19, 2008 08:54 PM
How to know which item was checked on tree?
Posted: Mon Sep 14, 2009 05:13 PM

Hi Guys,

Ive started to work under tree with checboxes, but i cant find an event that returns to me the item was checked.

I already tried oTree:bChanged and oTree:bChange but any of them works. When I tried oTree:OnClick its works just in a away, because i can`t get the item which was just checked.

Can some one give a hand?

Thanks,
Diego Imenes

regards,



Diego Imenes
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: How to know which item was checked on tree?
Posted: Mon Sep 14, 2009 07:18 PM

Diego,

Could you please provide an example PRG that shows the way you are doing it ? thanks

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 22
Joined: Mon May 19, 2008 08:54 PM
Re: How to know which item was checked on tree?
Posted: Mon Sep 14, 2009 08:08 PM
Antonio Linares wrote:Diego,

Could you please provide an example PRG that shows the way you are doing it ? thanks


Here it goes
Code (fw): Select all Collapse
#include "FiveWin.ch"

function Main()

   local oDlg, oTree

   DEFINE DIALOG oDlg

      oTree = TTreeView():New( 0, 0, oDlg,,,,,200,200,,.t.)

      oTree:OnClick = {|| msginfo(  oTree:GetSelected():cPrompt  , 1) }

   ACTIVATE DIALOG oDlg CENTERED ON INIT BuildTree( oTree )

   MsgInfo( oTree:aItems[ 1 ]:GetCheck() ) 

return nil 

function BuildTree( oTree ) 

   local oMenu := Array( 2 ), oSubMenu := Array( 3 ) 

   oMenu[ 1 ]:= oTree:Add( "Principal" ) 
      oSubMenu[ 1 ]:= oMenu[ 1 ]:Add( "Imprimir..." )
      oSubMenu[ 1 ]:SetCheck( .T. ) 

   oMenu[ 2 ]:= oTree:Add( "Proyectos" ) 
      oSubMenu[ 2 ]:= oMenu[ 2 ]:Add( "Definir Proyectos" ) 
      oSubmenu[ 3 ]:= oMenu[ 2 ]:Add( "Actualización datos" ) 

   oTree:Expand() 

return nil


Like going with the mouse or with the space bar to check a item i would like to SHOW which item was checked. I tried the getselected() but when you check a item, it doesn't become selected.


Thanks,
Diego
regards,



Diego Imenes
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: How to know which item was checked on tree?
Posted: Mon Sep 14, 2009 08:42 PM
Diego,

Here you have your example modified:
Code (fw): Select all Collapse
#include "FiveWin.ch"

function Main()

   local oDlg, oTree

   DEFINE DIALOG oDlg

      oTree = TTreeView():New( 0, 0, oDlg,,,,,200,200,,.t.)

      oTree:OnClick = { || CheckStatus( oTree, oTree:aItems ) }

   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" ) 
      oSubMenu[ 1 ]:= oMenu[ 1 ]:Add( "Imprimir..." )
      oSubMenu[ 1 ]:SetCheck( .T. ) 

   oMenu[ 2 ]:= oTree:Add( "Proyectos" ) 
      oSubMenu[ 2 ]:= oMenu[ 2 ]:Add( "Definir Proyectos" ) 
      oSubmenu[ 3 ]:= oMenu[ 2 ]:Add( "Actualización datos" ) 

   oTree:Expand() 

return nil 

function CheckStatus( oTree, aItems )

   local n
   
   for n = 1 to Len( aItems )
      MsgInfo( oTree:GetCheck( aItems[ n ] ) )
      CheckStatus( oTree, aItems[ n ]:aItems )
   next
   
return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 22
Joined: Mon May 19, 2008 08:54 PM
Re: How to know which item was checked on tree?
Posted: Mon Sep 14, 2009 08:50 PM

Antonio,

In this way i have done before. I really want to pick up that exactly item in the moment its checked.

When I check "Imprimir..." i want the message shows "Imprimir...". Just the item was checked and not all of them.

Is that possible?

regards,



Diego Imenes
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: How to know which item was checked on tree?
Posted: Mon Sep 14, 2009 09:02 PM
Diego,

Please check if this code is fine for what you want:
Code (fw): Select all Collapse
function CheckStatus( oTree, aItems )

   local n
   
   for n = 1 to Len( aItems )
      if oTree:GetCheck( aItems[ n ] )
         MsgInfo( aItems[ n ]:cPrompt )
      endif   
      CheckStatus( oTree, aItems[ n ]:aItems )
   next
   
return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 22
Joined: Mon May 19, 2008 08:54 PM
Re: How to know which item was checked on tree?
Posted: Tue Sep 15, 2009 11:04 AM
Antonio,

Almost this! Because its shows all items that are checked and i wanna show just the item was checked in each moment.

I don`t know if I express myself well. So being more exactly:

The tree is there with all items, so i check "Imprimir..." and the function shows for me just "Imprimir..."
So i check "Definir Proyectos" and the function shows for me just "Definir Proyectos"


______________________________________


Antonio I`m reading the overview of TreeView classe at MSDN:

http://msdn.microsoft.com/pt-br/library ... view(VS.80).aspx

So I found this part that I think is what I`m looking for....

Setting the TreeNode.Checked property from within the BeforeCheck or AfterCheck event causes the event to be raised multiple times and can result in unexpected behavior.For example, you might set the Checked property in the event handler when you are recursively updating the child nodes, so the user does not have to expand and check each one individually.To prevent the event from being raised multiple times, add logic to your event handler that only executes your recursive code if the Action property of the TreeViewEventArgs is not set to TreeViewAction.Unknown.For an example of how to do this, see the Example section of the AfterCheck or BeforeCheck events.
regards,



Diego Imenes
Posts: 22
Joined: Mon May 19, 2008 08:54 PM
Re: How to know which item was checked on tree?
Posted: Thu Sep 17, 2009 11:25 AM

Antonio?

regards,



Diego Imenes
Posts: 663
Joined: Mon Dec 05, 2005 11:22 PM
Re: How to know which item was checked on tree?
Posted: Thu Apr 07, 2011 08:48 PM

Has this ever been resolved. I find myself needing to know which node the user changed.
Wwen the user checks or unchecks the node it does not select the node so I cant tell which one was changed.

Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: How to know which item was checked on tree?
Posted: Thu Apr 07, 2011 09:00 PM
Posts: 663
Joined: Mon Dec 05, 2005 11:22 PM
Re: How to know which item was checked on tree?
Posted: Thu Apr 07, 2011 10:08 PM

The problem is different. When you use the check boxes and you use the mouse to click on the checkbox it does not make that node selected. So you cannot tell which node was actually checked. I can tell which node is selected but that is a different issue.

Continue the discussion