Sign in to follow this  
Followers 0
JoeCool

Is there something like _guiCtrlTreeViewItemGetParent ?

5 posts in this topic

HI :-)

Is there something like _guiCtrlTreeViewItemGetParent ( $treeView, $treeViewItem )

somewhere ?

Share this post


Link to post
Share on other sites



Sample:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TreeViewConstants.au3>

opt("MustDeclareVars", 1)

Dim $tree, $item1, $subitem1, $subitem2, $item2, $subitem3, $subitem4, $button, $msg, $Status, $parent
GUICreate("GuiTreeView Get Parent ID", 392, 254)
$tree = GUICtrlCreateTreeView(10, 10, 200, 200)
$item1 = GUICtrlCreateTreeViewItem("Mainitem1", $tree)
$subitem1 = GUICtrlCreateTreeViewItem("Subitem11", $item1)
$subitem2 = GUICtrlCreateTreeViewItem("Subitem12", $item1)
$item2 = GUICtrlCreateTreeViewItem("Mainitem2", $tree)
$subitem3 = GUICtrlCreateTreeViewItem("Subitem21", $item2)
$subitem4 = GUICtrlCreateTreeViewItem("Subitem22", $item2)
$button = GUICtrlCreateButton("Check", 220, 100, 70, 20)
$Status = GUICtrlCreateLabel("", 0, 234, 392, 20, BitOR($SS_SUNKEN, $SS_CENTER))

GUISetState()
While 1
   $msg = GUIGetMsg()
   Select
      Case $msg = $GUI_EVENT_CLOSE
         ExitLoop
      Case $msg = $button
         Msgbox(0, "Info", "ParentID from selected: " & _MyGUICtrlTreeViewGetParentID($tree) & @LF & _
                            "ParentID from $subitem2: " & _MyGUICtrlTreeViewGetParentID($tree, $subitem2))
   EndSelect
WEnd
Exit


Func _MyGUICtrlTreeViewGetParentID($nTreeview, $hItem = 0)
    If $hItem = 0 Then
        $hItem = GUICtrlSendMsg($nTreeview, $TVM_GETNEXTITEM, $TVGN_CARET, 0)
    Else
        Local $hItemTmp = GUICtrlGetHandle($hItem)
        If $hItemTmp <> 0 Then $hItem = $hItemTmp
    EndIf
    
    If $hItem = 0 Then Return 0
    
    Local $hParent = GUICtrlSendMsg($nTreeview, $TVM_GETNEXTITEM, $TVGN_PARENT, $hItem)

    Local $stTVITEM = DllStructCreate("uint;dword;uint;uint;ptr;int;int;int;int;dword")
    DllStructSetData($stTVITEM, 1, $TVIF_PARAM)
    DllStructSetData($stTVITEM, 2, $hParent)
    
    If GUICtrlSendMsg($nTreeview, $TVM_GETITEM, 0, DllStructGetPtr($stTVITEM)) = 0 Then Return 0
    
    Return DllStructGetData($stTVITEM, 10)
EndFunc

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Sample:

Func _MyGUICtrlTreeViewGetParentID($nTreeview, $hItem = 0)
    If $hItem = 0 Then
        $hItem = GUICtrlSendMsg($nTreeview, $TVM_GETNEXTITEM, $TVGN_CARET, 0)
    Else
        Local $hItemTmp = GUICtrlGetHandle($hItem)
        If $hItemTmp <> 0 Then $hItem = $hItemTmp
    EndIf
    
    If $hItem = 0 Then Return 0
    
    Local $hParent = GUICtrlSendMsg($nTreeview, $TVM_GETNEXTITEM, $TVGN_PARENT, $hItem)

    Local $stTVITEM = DllStructCreate("uint;dword;uint;uint;ptr;int;int;int;int;dword")
    DllStructSetData($stTVITEM, 1, $TVIF_PARAM)
    DllStructSetData($stTVITEM, 2, $hParent)
    
    If GUICtrlSendMsg($nTreeview, $TVM_GETITEM, 0, DllStructGetPtr($stTVITEM)) = 0 Then Return 0
    
    Return DllStructGetData($stTVITEM, 10)
EndFunc

Hey Thanks ;-)

I was in a process to build something like that because I want to find parent treeViewItem of an unselected

item, the current UDF only implement for selected item !

I was good until I have to convert the parent handle to an ID .

Some people suggest

http://www.autoitscript.com/forum/index.php?showtopic=30285My Webpage

but it seems that isn't working for treeviewitem ....

I'm gonna study your last part of your function ;-)

BTW, why not include your function into the current UDF ?

Edited by JoeCool

Share this post


Link to post
Share on other sites

Hey Thanks ;-)

I was in a process to build something like that because I want to find parent treeViewItem of an unselected

item, the current UDF only implement for selected item !

I was good until I have to convert the parent handle to an ID .

Some people suggest

http://www.autoitscript.com/forum/index.php?showtopic=30285My Webpage

but it seems that isn't working for treeviewitem ....

I'm gonna study your last part of your function ;-)

BTW, why not include your function into the current UDF ?

Keep an eye out, if it isn't and Holger wrote it, then it probably will be :whistle:.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

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  
Followers 0