How to know which item was checked on tree?

Post Reply
dempty
Posts: 22
Joined: Mon May 19, 2008 8:54 pm

How to know which item was checked on tree?

Post by dempty »

Hi Guys,

I`ve started to work under tree with checboxes, but i can`t 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
User avatar
Antonio Linares
Site Admin
Posts: 42556
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 80 times
Contact:

Re: How to know which item was checked on tree?

Post by Antonio Linares »

Diego,

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

Antonio Linares
www.fivetechsoft.com
dempty
Posts: 22
Joined: Mon May 19, 2008 8:54 pm

Re: How to know which item was checked on tree?

Post by dempty »

Antonio Linares wrote:Diego,

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


Here it goes

Code: Select all | Expand


#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
User avatar
Antonio Linares
Site Admin
Posts: 42556
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 80 times
Contact:

Re: How to know which item was checked on tree?

Post by Antonio Linares »

Diego,

Here you have your example modified:

Code: Select all | Expand


#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
dempty
Posts: 22
Joined: Mon May 19, 2008 8:54 pm

Re: How to know which item was checked on tree?

Post by dempty »

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
User avatar
Antonio Linares
Site Admin
Posts: 42556
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 80 times
Contact:

Re: How to know which item was checked on tree?

Post by Antonio Linares »

Diego,

Please check if this code is fine for what you want:

Code: Select all | Expand


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
dempty
Posts: 22
Joined: Mon May 19, 2008 8:54 pm

Re: How to know which item was checked on tree?

Post by dempty »

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
dempty
Posts: 22
Joined: Mon May 19, 2008 8:54 pm

Re: How to know which item was checked on tree?

Post by dempty »

Antonio?
regards,

Diego Imenes
Gale FORd
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston
Contact:

Re: How to know which item was checked on tree?

Post by Gale FORd »

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.
User avatar
Daniel Garcia-Gil
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:

Re: How to know which item was checked on tree?

Post by Daniel Garcia-Gil »

our best documentation is the source code
Isla de Margarita Venezuela.
danielgarciagil@gmail.com
http://tdolphin.blogspot.com/
https://www.dropbox.com/referrals/NTI5N ... rc=global9
Gale FORd
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston
Contact:

Re: How to know which item was checked on tree?

Post by Gale FORd »

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.
Post Reply