TREE

HMG en Español

Moderator: Rathinagiri

Post Reply
User avatar
SALINETAS24
Posts: 667
Joined: Tue Feb 27, 2018 3:06 am
DBs Used: DBF
Contact:

TREE

Post by SALINETAS24 »

Hola
¿hay alguna forma de saber las líneas que se están visualizando en un TREE?
SOLO LAS LINEAS QUE SE VEN.
Gracias
Como dijo el gran pensador Hommer Simpson..., - En este mundo solo hay 3 tipos de personas, los que saben contar y los que no. :shock:
ASESORMIX
Posts: 195
Joined: Thu Oct 25, 2012 8:08 pm
Location: Bqto, Venezuela

Re: TREE

Post by ASESORMIX »

Hola a Todos.
Como podría aplicar Form_1.Tree_1.GetPathName (n) en hmg extended ?
User avatar
gfilatov
Posts: 1082
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: TREE

Post by gfilatov »

ASESORMIX wrote: Thu May 04, 2023 9:57 pm Hola a Todos.
Como podría aplicar Form_1.Tree_1.GetPathName (n) en hmg extended ?
Hola,

Thanks for your request ;)

Please take a look at the working sample below :arrow:

Code: Select all

#include "hmg.ch"

FUNCTION Main()

   DEFINE WINDOW Form_1 ;
         WIDTH 800 ;
         HEIGHT 600 ;
         NOSIZE ;
         NOMAXIMIZE ;
         ON GOTFOCUS Form_1.Tree_1.SetFocus ;
         MAIN

      DEFINE TREE Tree_1 ;
            AT 10, 10 ;
            WIDTH 250 ;
            HEIGHT 550 ;
            VALUE 1 ;
            FONT "Calibri" SIZE 12 ;
            ON CHANGE OnChangeTree ( This.Value ) ;
            NODEIMAGES { "folder.bmp", "folder_page.bmp" } ;
            ITEMIMAGES { "Page.bmp", "page_next.bmp" } ;
            NOROOTBUTTON

         NODE 'MY APP       [F9]'

            NODE 'BOOK      [F1]'
               TREEITEM 'Science'
               TREEITEM 'Literature'
            END NODE

            NODE 'MUSIC     [F2]'
               TREEITEM 'Rock'
               TREEITEM 'Classic'
            END NODE

            NODE 'VIDEOS    [F3]'
               TREEITEM 'Documentary'
               TREEITEM 'Series'
               TREEITEM 'Sports'
            END NODE

            NODE 'EMAIL      [F4]'
               TREEITEM 'Send'
               TREEITEM 'Inbox'
               TREEITEM 'Outbox'
               TREEITEM 'Drafts'
               TREEITEM 'Spam'
               TREEITEM 'Sent Items'
               NODE 'OTHER'
                  TREEITEM 'Backup'
                  TREEITEM 'Calendar'
               END NODE
            END NODE

            NODE 'ABOUT...  [F5]'
            END NODE

         END NODE
      END TREE

   END WINDOW

   OnChangeTree ( 1 )
   Form_1.Tree_1.Expand ( 1 )

   ON KEY F1 OF Form_1 ACTION OnKeyFx ( 2 )
   ON KEY F2 OF Form_1 ACTION OnKeyFx ( 5 )
   ON KEY F3 OF Form_1 ACTION OnKeyFx ( 8 )
   ON KEY F4 OF Form_1 ACTION OnKeyFx ( 12 )
   ON KEY F5 OF Form_1 ACTION OnKeyFx ( 22 )

   ON KEY F9 OF Form_1 ACTION ( Form_1.Tree_1.VALUE := 1, OnChangeTree ( 1 ), ;
      IF ( Form_1.Tree_1.IsExpand ( Form_1.Tree_1.Value ) == .T., ;
      Form_1.Tree_1.Collapse ( Form_1.Tree_1.VALUE, .T. ), ; // Collapse All
   Form_1.Tree_1.Expand ( Form_1.Tree_1.VALUE, .T. ) ) ) // Expand All

   CENTER WINDOW Form_1
   ACTIVATE WINDOW Form_1

RETURN NIL


FUNCTION OnKeyFx ( nItem )

   OnChangeTree( nItem )

   Form_1.Tree_1.VALUE := nItem
   IF Form_1.Tree_1.IsExpand( Form_1.Tree_1.Value )
      Form_1.Tree_1.Collapse( Form_1.Tree_1.Value )
   ELSE
      Form_1.Tree_1.Expand( Form_1.Tree_1.Value )
   ENDIF

RETURN NIL


FUNCTION OnChangeTree ( nItem )

   DO CASE
   CASE nItem = 1
   CASE nItem = 2
   CASE nItem = 3
   // CASE nOption 4 to 22  ....
   ENDCASE

   Form_1.TITLE := "#" + hb_ntos( nItem ) + " --> " + hb_ValToExp( TreeItemGetPathName( "Tree_1", "Form_1", nItem ) )

RETURN NIL


FUNCTION TreeItemGetPathValue ( ControlName, ParentForm, nItem )

   LOCAL ParentItem, aPathValues
   LOCAL nControlHandle := GetControlHandle ( ControlName, ParentForm )
   LOCAL ItemHandle := TreeItemGetHandle ( ControlName, ParentForm, nItem )

   IF ItemHandle <> 0
      aPathValues := { nItem }
      ParentItem := TreeView_GetParent ( nControlHandle, ItemHandle )
      WHILE ( ParentItem <> 0 )
         AAdd ( aPathValues, NIL )
         AIns ( aPathValues, 1 )
         aPathValues[ 1 ] := TreeItemGetValueByItemHandle ( ControlName, ParentForm, ParentItem )
         ParentItem := TreeView_GetParent ( nControlHandle, ParentItem )
      END
   ENDIF

RETURN aPathValues


FUNCTION TreeItemGetPathName ( ControlName, ParentForm, nItem )

   LOCAL aPathName
   LOCAL aPathValues := TreeItemGetPathValue ( ControlName, ParentForm, nItem )

   IF ValType ( aPathValues ) == "A"
      aPathName := TreeItemGetItemText ( ControlName, ParentForm, aPathValues )
   ENDIF

RETURN aPathName


FUNCTION TreeItemGetItemText ( ControlName, ParentForm, aItem )

   LOCAL k, cText, aItemsText

   IF ValType ( aItem ) == "A"
      aItemsText := {}
      FOR k = 1 TO HMG_LEN ( aItem )
         cText := GetProperty ( ParentForm, ControlName, "Item", aItem[ k ] )
         AAdd ( aItemsText, cText )
      NEXT
   ENDIF

RETURN aItemsText


FUNCTION TreeItemGetValueByItemHandle ( ControlName, ParentForm, ItemHandle )

   LOCAL nPos, nID
   LOCAL nControlHandle := GetControlHandle ( ControlName, ParentForm )
   LOCAL i

   IF ( i := GetControlIndex ( ControlName, ParentForm ) ) > 0 .AND. ItemHandle <> 0
      IF _HMG_aControlInputMask[ i ] == .F.
         nPos := AScan ( _HMG_aControlPageMap[ i ], ItemHandle )
         RETURN nPos
      ELSE
         nID := TREEITEM_GETID ( nControlHandle, ItemHandle )
         RETURN nID
      ENDIF
   ENDIF

RETURN NIL
Hope that helps. :idea:
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
ASESORMIX
Posts: 195
Joined: Thu Oct 25, 2012 8:08 pm
Location: Bqto, Venezuela

Re: TREE

Post by ASESORMIX »

Big Thank Friend.
Very Useful for me.
User avatar
mol
Posts: 3727
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: TREE

Post by mol »

I want to refresh this topic, but my question is a little differnt.
I want to build left side menu based on tree control, but I want the treelines are invisible. Also + and - for expand/collapse tree should be invisible.
Does anybody have information how to do it?
Last edited by mol on Fri Feb 09, 2024 8:43 pm, edited 1 time in total.
User avatar
gfilatov
Posts: 1082
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: TREE

Post by gfilatov »

mol wrote: Fri Feb 09, 2024 3:10 pm I want to refresh this topic, but my question is a little differnt.
I want to build left side menu based on tree control, but I want the treelines are invisible. Also + and - for expand/collapse tree should be invisible.
Does anybody information how to do it?
Hi Marek,

Yes, it is possible.
Try to use
HMG_ChangeWindowStyle (Form_1.Tree_1.HANDLE, NIL, TVS_HASBUTTONS, .F.)
HMG_ChangeWindowStyle (Form_1.Tree_1.HANDLE, NIL, TVS_HASLINES, .F.)
See my result in the picture below:
image.png
image.png (17.74 KiB) Viewed 1764 times
Hope that helps. :idea:
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
User avatar
mol
Posts: 3727
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: TREE

Post by mol »

:lol: You're really amazing, guy :lol:

Thank you very much!
User avatar
mol
Posts: 3727
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: TREE

Post by mol »

Is it the way to remove highlighting of current item?

DynamicBackColor or something else?
Post Reply