Jump to content
Sign in to follow this  
ledigeine

get tree path/value

Recommended Posts

ledigeine

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.

Share this post


Link to post
Share on other sites
spudw2k

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.

Share this post


Link to post
Share on other sites
ledigeine

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.

Share this post


Link to post
Share on other sites
water

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 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
spudw2k

$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
  • Like 1

Share this post


Link to post
Share on other sites
ledigeine

Thank you both, very very helpful!

I might get this utility working one day!

Share this post


Link to post
Share on other sites
ledigeine

$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?

Share this post


Link to post
Share on other sites
spudw2k

Can you provide more code to test with? I'm not sure why it is producing the string in that manner.

Edited by spudw2k

Share this post


Link to post
Share on other sites
ledigeine

#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)

Share this post


Link to post
Share on other sites
spudw2k

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
  • Like 1

Share this post


Link to post
Share on other sites
ledigeine

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!

Share this post


Link to post
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
Sign in to follow this  

×