Jump to content

Treeview - Count of Items


fifi
 Share

Recommended Posts

Hi,

is it also possible to count the items of a mainitem?

The UDF _GUICtrlTreeViewGetCount in beta 56 does not work if there is given a control-id of a mainitem as param (for example $mainitem2) :-(

Has anybody an idea?

Thanks

FIFI

Link to comment
Share on other sites

This only counts the children of item selected not it's childrens children etc...

#include <GUIConstants.au3>
#include <GuiTreeView.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
         GUICtrlSetData($Status, "# Children: " & _GUICtrlTreeViewCountChildren($tree))
   EndSelect
WEnd
Exit


Func _GUICtrlTreeViewCountChildren($h_treeview)
    Local $count = 0, $hItem,$h_item
    $hItem  = GUICtrlSendMsg($h_treeview,$TVM_GETNEXTITEM,$TVGN_CARET,0)
    $h_item = GUICtrlSendMsg($h_treeview, $TVM_GETNEXTITEM, $TVGN_CHILD, $hItem)
    Do
        If ($h_item > 0) Then
            $count = $count + 1
        EndIf
        $h_item = GUICtrlSendMsg($h_treeview, $TVM_GETNEXTITEM, $TVGN_NEXT, $h_item)
    Until $h_item <= 0
    Return $count
EndFunc
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.

 

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...