Jump to content

get tree path/value


Recommended Posts

Hello, been working on this utility for a while now and just found out there is a Tree UI option so i'm messing with that now. It could make everything a lot easier.

So i have my tree here, 3 main options with several versions under them. Then country options under each version.

post-71985-0-41042800-1337610085_thumb.j

How would i return a value for the item that is highlighted? So i would need to see its, Testassigned/12.0/US.

Because based on each item I will need to pull a value from an XML file so i can map 2 drives correctly.

Thank you for any help you can give.

Link to comment
Share on other sites

I once made a function to do that, but I am struggling to find where it is.

There are functions in the GUICtrlTreeView UDF that will get you there.

I can't remember the functions but the logic goes like this.

One function will return the id/index of the selected item.

Another will retrieve the text value if the item.

Then a function determines the selected id/indexes parent,

Rinse repeat until no more parents are found.

If I come across my _TreeToPath function I'll post it.

Link to comment
Share on other sites

Thanks! Yeah before this i was using radio buttons and lists, I think a tree will be way easier for a user to understand. And this way there wont be a bunch of different conditions its all based on one element.

I should see if theres a way to make the main parts of the tree not selectable, so a user would know you can only pick the end of the tree or something like that.

Link to comment
Share on other sites

Please have a look at my _AD_Example_GetOUTreeView example script. It displays an Active Directory treeview of all OUs and when an OU is selected it returns the name plus the FQDN.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

$selection = _GUICtrlTreeView_GetSelection($hWnd)
$txt = _TreePath($hWnd,$selection)

Func _TreePath($hWnd, $item) ;Determine full path of selected item in TreeView
    $txt = _GUICtrlTreeView_GetText($hWnd, $item)
    Do
        $parent = _GUICtrlTreeView_GetParentHandle($hWnd, $item)
        If $parent > 0 Then
            $txt = _GUICtrlTreeView_GetText($hWnd, $parent) & "" & $txt
            $item = $parent
        EndIf
    Until $parent = 0
    Return StringTrimLeft($txt,StringInstr($txt,""))
EndFunc   ;==>;_TreePath

edit: 1000th post. ;)

Edited by spudw2k
Link to comment
Share on other sites

$selection = _GUICtrlTreeView_GetSelection($treeview)
$txt = _TreePath($treeview,$selection)
Func _TreePath($treeview, $item) ;Determine full path of selected item in TreeView
    $txt = _GUICtrlTreeView_GetText($treeview, $item)
    Do
        $parent = _GUICtrlTreeView_GetParentHandle($treeview, $item)
        If $parent > 0 Then
            $txt = _GUICtrlTreeView_GetText($treeview, $parent) & "\" & $txt
            $item = $parent
        EndIf
    Until $parent = 0
    Return StringTrimLeft($txt,StringInstr($txt,"\"))
EndFunc   ;==>;_TreePath

I got this going on, didnt really have to change much thanks to spudw2k. When running this on my script im getting an issue. Its pulling the 'parent' i think youd call it, then the child as well but its not pulling the childs child... hah.

Heres a screen shot.

post-71985-0-61123600-1337631562_thumb.j

So I would really need it to display Testassigned then 12.0 then US. Even if there was another option under US i would also need that displayed.

How could i make it keep checking and reading until its at the end of the tree?

Link to comment
Share on other sites

Link to comment
Share on other sites

#include <GuiTreeView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
Global $txt, $item
EBTAM()
Func EBTAM()
   Global $treeview, $mapB, $ass, $app, $shp
  
   GUICreate("EB TAM", 600, 400)
   GUISetState(@SW_SHOW)
   $treeview = GUICtrlCreateTreeView(20, 15, 560, 325, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
   $ass = GUICtrlCreateTreeViewItem("Test Assigned", $treeview)
   $app = GUICtrlCreateTreeViewItem("Testing Approved", $treeview)
   $shp = GUICtrlCreateTreeViewItem("Shipped", $treeview)
  
   testassigned()
   testingapproved()
   shipped()
  
   $mapB = GUICtrlCreateButton("&Map", 20, 350, 120, 40)
  
  
;~  GUICtrlSetState($ass, $GUI_EXPAND)
   While 1
   $msg = GUIGetMsg()
   Switch $msg
   Case $GUI_EVENT_CLOSE
   Exit
   Case $mapB
   MsgBox(0, "node selected", "Node: " & _TreePath($treeview, $item))
   EndSwitch
   WEnd
EndFunc
$selection = _GUICtrlTreeView_GetSelection($treeview)
$txt = _TreePath($treeview,$selection)
Func _TreePath($treeview, $item) ;Determine full path of selected item in TreeView
    $txt = _GUICtrlTreeView_GetText($treeview, $item)
    Do
        $parent = _GUICtrlTreeView_GetParentHandle($treeview, $item)
        If $parent > 0 Then
            $txt = _GUICtrlTreeView_GetText($treeview, $parent) & "\" & $txt
            $item = $parent
        EndIf
    Until $parent = 0
    Return StringTrimLeft($txt,StringInstr($txt,"\"))
EndFunc   ;==>;_TreePath

thats most of it, just didnt wana put the fuctions for making the items in the list... they are long ha.

Heres a little taste of it:

Func testassigned()

Local $120, $111, $110, $108, $107, $106, $105, $104, $103, $102, $101, $100, $94, $93, $92, $91

$120 = GUICtrlCreateTreeViewItem("12.0", $ass)

GUICtrlCreateTreeViewItem("US", $120)

GUICtrlCreateTreeViewItem("CA", $120)

GUICtrlCreateTreeViewItem("UK", $120)

Link to comment
Share on other sites

This seems to work. Had to modify _TreePath slightly.

#include <GuiTreeView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
Global $txt, $item
EBTAM()
Func EBTAM()
   Global $treeview, $mapB, $ass, $app, $shp

   GUICreate("EB TAM", 600, 400)
   $treeview = GUICtrlCreateTreeView(20, 15, 560, 325, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
   $ass = GUICtrlCreateTreeViewItem("Test Assigned", $treeview)
   $app = GUICtrlCreateTreeViewItem("Testing Approved", $treeview)
   $shp = GUICtrlCreateTreeViewItem("Shipped", $treeview)

   $120 = GUICtrlCreateTreeViewItem("12.0", $ass)
   GUICtrlCreateTreeViewItem("US", $120)
   GUICtrlCreateTreeViewItem("CA", $120)
   GUICtrlCreateTreeViewItem("UK", $120)

   $mapB = GUICtrlCreateButton("&Map", 20, 350, 120, 40)
   GUISetState(@SW_SHOW)

   While 1
   $msg = GUIGetMsg()
   Switch $msg
   Case $GUI_EVENT_CLOSE
   Exit
   Case $mapB
   MsgBox(0, "node selected", "Node: " & _TreePath($treeview, $item))
   EndSwitch
   WEnd
EndFunc



Func _TreePath($treeview, $item) ;Determine full path of selected item in TreeView
    $item = _GUICtrlTreeView_GetSelection($treeview)
    $txt = _GUICtrlTreeView_GetText($treeview, $item)
    Do
        $parent = _GUICtrlTreeView_GetParentHandle($treeview, $item)
        $txt = _GUICtrlTreeView_GetText($treeview, $parent) & "" & $txt
        $item = $parent
    Until $parent = 0
    Return StringTrimLeft($txt,StringInstr($txt,""))
EndFunc   ;==>;_TreePath
Link to comment
Share on other sites

Wow there we go thanks so much!

I think i should be able to figure out how to split the string up so i get the pieces i need. Then refer to the xml pulling script to match each part with a section of a path that this uitliy will map a drive to.

Thank you again!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...