How to know which item was checked on tree?

How to know which item was checked on tree?

Postby dempty » Mon Sep 14, 2009 5:13 pm

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

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

Postby Antonio Linares » Mon Sep 14, 2009 7: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42082
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby dempty » Mon Sep 14, 2009 8: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: Select all  Expand view

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

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

Postby Antonio Linares » Mon Sep 14, 2009 8:42 pm

Diego,

Here you have your example modified:
Code: Select all  Expand view

#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
User avatar
Antonio Linares
Site Admin
 
Posts: 42082
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

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

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

Postby Antonio Linares » Mon Sep 14, 2009 9:02 pm

Diego,

Please check if this code is fine for what you want:
Code: Select all  Expand view

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
User avatar
Antonio Linares
Site Admin
 
Posts: 42082
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

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

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

Postby dempty » Thu Sep 17, 2009 11:25 am

Antonio?
regards,

Diego Imenes
dempty
 
Posts: 22
Joined: Mon May 19, 2008 8:54 pm

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

Postby Gale FORd » Thu Apr 07, 2011 8: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.
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

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

Postby Daniel Garcia-Gil » Thu Apr 07, 2011 9:00 pm

User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

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

Postby Gale FORd » 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.
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 95 guests