Jump to content
Sign in to follow this  


Recommended Posts


again i have a special "problem".

I tried very hard to build a UDF for treeview which returns the ordnernumber of the clicked subitem, but i had no success after some hours of work.

I try to explain this problem:

- Mainitem1



- Mainitem2




- Mainitem3

For example if Subitem22 is clicked i need to know that it is the second Subitem. So the UDF should return "2". And so on!

Maybe there is a simple way to do this; based on the functions that holger and gafrost have made for treeview the last days?



Share this post

Link to post
Share on other sites

#include <GUIConstants.au3>
#include <GuiTreeView.au3>
opt ("MustDeclareVars", 1)

Dim $tree, $item1, $subitem1, $subitem2, $item2, $subitem3, $subitem4, $button, $msg, $Status, $parent
GUICreate("GuiTreeView Child #", 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))

While 1
    $msg = GUIGetMsg()
        Case $msg = $GUI_EVENT_CLOSE
        Case $msg = $button
            GUICtrlSetData($Status, "Child #: " & _GUICtrlTreeViewSubItemSelected($tree))

Func _GUICtrlTreeViewSubItemSelected($h_treeview)
    Local $count = 1, $h_PItem, $hItem, $h_item
    $hItem = GUICtrlSendMsg($h_treeview, $TVM_GETNEXTITEM, $TVGN_CARET, 0)
    If $hItem == 0 Then Return 0
    $h_PItem = GUICtrlSendMsg($h_treeview, $TVM_GETNEXTITEM, $TVGN_PARENT, $hItem)
    $h_item = GUICtrlSendMsg($h_treeview, $TVM_GETNEXTITEM, $TVGN_CHILD, $h_PItem)
        If ($h_item > 0 And $hItem <> $h_item) Then
            $h_item = GUICtrlSendMsg($h_treeview, $TVM_GETNEXTITEM, $TVGN_NEXT, $h_item)
            $count = $count + 1
    Until $h_item == 0
    Return $count
EndFunc  ;==>_GUICtrlTreeViewSubItemSelected

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs


Don't argue with an idiot; people watching may not be able to tell the difference.


Share this post

Link to post
Share on other sites

Hi gafrost,

thanks for quick helping. Hope this was the last enhancement i needed for treeview.

It works perfectly and i think for other users can your UDF's also be very usefull.


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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...