Jump to content

GUI Treeview questions


ReFran
 Share

Recommended Posts

Hello,

I want to use a treeview to let a user set up or change the bookmarks for a PDF.

1.) Get Root ID = ID of first treeview item

Because I read the data from a selectable PDF, after the GUI with different TABs, btns ... is created, the root ID = ID of the first tv-item is different from the $treeview ID. The difference are all the other GUI elements I created after the empty treeview. At time I use GUICtrlRead($treeview)+14. Smarter would be to get it direct.

2.) Insert item

I found in the helpfile nothing about it. I want to let the user insert a new tv-item direct after the selected or if nothing is selected at the end.

3.)Read out treeview items with levels

Finaly I want to read out the items with level (mother, child,..) to transfer it into a PDF.

I looked at the treeview UDFs and tried also some changement of the given commands, but didn't get it to work. Is there somewhere a Doku from MS.

Best regards, Reinhard

Edited by ReFran
Link to comment
Share on other sites

Look at my example treeview_item_state_example.au3

where I'm using TVM_GETNEXTITEM & TVGN_xxx

It's what you need ...

http://www.autoitscript.com/forum/index.ph...topic=18409&hl=

Take it as a start point and modify it to your needs.

Hi,

thanks for hint. Saw it already. Sounds workfull. How to get the level (asking every item if it has a child - with which statement -). Are there any (MS) dcoumentation about the used constants, TVM_GETNEXTITEM & TVGN_xxx.

Seem to become an interesting week for a finance guy and hobbyscripter.

Have to sleep some few hours, Reinhard

Link to comment
Share on other sites

Hi,

thanks for hint. Saw it already. Sounds workfull. How to get the level (asking every item if it has a child - with which statement -). Are there any (MS) dcoumentation about the used constants, TVM_GETNEXTITEM & TVGN_xxx.

Seem to become an interesting week for a finance guy and hobbyscripter.

Have to sleep some few hours, Reinhard

You can find if item has child by _TreeViewGetItemState.au3

look at www.msdn.com in search edit type name of WIN API function of your interest:

TVM_GETNEXTITEM

TVM_GETITEM

EDIT:

You can find if item has child by TVM_GETITEM & TVIF_CHILDREN

(and not TVM_GETITEM & TVIF_STATE)

Edited by Zedna
Link to comment
Share on other sites

.....

You can find if item has child by TVM_GETITEM & TVIF_CHILDREN

.....

Hello,

found something at: http://support.microsoft.com/default.aspx?...kb;en-us;155895

But reading this C++ example, your statements and the treeview UDFs, I got the impression that I have to learn more about GuiCtrlSendmessage and also perhaps about DLLCalls to puzzle some working code together.

Because I've also some other - more urgent - projects on work, I will use for the bookmarks(/treeview) edit a third party tool/gui (PDFMetaEdit) until I find the time to understand and use all the information I got and gathered.

If you find sometime a helpfile for the "commctrl" let me know. I found only one for the ComCtrl.tree.1 object which is defined in the ComCtl32.Ocx (comCtl1.hlp).

Thanks for your support, Reinhard

PS: Until I get sometime my PDF project ready you may use PDFasm and PDFMetaEdit from http://www.becyhome.de/download_eng.htm#becypdfasm

(if you have to work with PDFs).

Edited by ReFran
Link to comment
Share on other sites

Ok, did it ....

... attached the basic/raw code to read out all treeview items structured. I did it by reading all levels, but with today knowledge I think I could do it also with reading the tree structure down.

However, if you look at the code it shows you how you can get the handle to every item, which may be helpful in some situations. So read out and read in is not a problem and give you all possibilities to work with a treeview.

Also from the code you can see, that I'm don't really can be called a expert for writing nested loops and to work with arrays.

So improvements or a UDF (_GetTreeViewAllItemsStructured) are welcome, Reinhard.

#include <GUIConstants.au3>
#include <GuiTreeView.au3>

const $TVGN_ROOT = 0

DIM $result = ""
DIM $level = 0
DIM $text 
DIM $SubResult = ""
DIM $ParentNO = ""
DIM $ItemID[10]

$gui = GUICreate("Treeview Read",212,212)
$treeview = GUICtrlCreateTreeView (6,6,200,160,BitOr($TVS_HASBUTTONS,$TVS_HASLINES,$TVS_LINESATROOT,$TVS_CHECKBOXES),$WS_EX_CLIENTEDGE)
$h_tree = ControlGetHandle("", "", $treeview)

$root = GUICtrlCreateTreeViewitem ("Mother1",$treeview)
$item1 = GUICtrlCreateTreeViewitem ("Item 11",$root)
$item2 = GUICtrlCreateTreeViewitem ("Item 12",$root)
$item3 = GUICtrlCreateTreeViewitem ("Item 13",$root)
$item31 = GUICtrlCreateTreeViewitem ("Item 131",$item3) 
$item32 = GUICtrlCreateTreeViewitem ("Item 132",$item3)
$item4 = GUICtrlCreateTreeViewitem ("Item 14",$root)
$item5 = GUICtrlCreateTreeViewitem ("Mother2",$treeview)
$item51 = GUICtrlCreateTreeViewitem ("Item 21",$item5)
$item52 = GUICtrlCreateTreeViewitem ("Item 22",$item5)
$item6 = GUICtrlCreateTreeViewitem ("Mother3",$treeview)

GUICtrlSetState($item2,$GUI_CHECKED) 
GUICtrlSetState($item4,$GUI_CHECKED) 
_GUICtrlTreeViewExpand($gui, $treeview, 1, 0)

$show = GUICtrlCreateButton("Show", 70, 180, 70, 20)

GUISetState ()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $show
            Show()
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd
GUIDelete()
Exit

;;;;;;;;;;;;;; List all Treeview items;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; The Treeview items will be read out by level. 
;;    (First all Mothers, then Childs on first Level, second level ...  
;;Therefor a PositionNo is added and for the chields also the parentNo
;;  (finaly it can be sorted to view it like the in the treeview
;; The positionNo is set to 10, so 99 items on every level are possible 
;;    (perhaps $pos = 100 is better)
;; To Do:
;; Take out Count and ItemIDs from result, Split result and sort array.
;; A global counter so that loops are finished if count result = $itemCount
;; Set up a loop for the searchChilds($level) until the count result = $itemCount
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;




Func Show()
    $itemCount = _GUICtrlTreeViewGetCount($treeview)
    $result = "Count: "&$ItemCount &@lf
    if $itemCount = 0 then return
    DIM $aItemID;store the itemnumber
    
    
    $level = 1
    $pos = 10
    $h_item0 = GUICtrlSendMsg($treeview, $TVM_GETNEXTITEM, $TVGN_ROOT, 0)
        $text = $ParentNO&$pos& _TreeViewGetItemText($h_tree, $h_item0)
        $result &= $h_item0 &":" &$text &@LF
        $ItemID[$level] = $h_item0 &";" &$pos &";"
    While 1  ;get all Mothers from Root level
        $pos += +1
        $h_item0 = GUICtrlSendMsg($treeview, $TVM_GETNEXTITEM, $TVGN_NEXT, $h_item0)
        $text = $ParentNO&$pos& _TreeViewGetItemText($h_tree, $h_item0)
        If $h_item0 <= 0 Then ExitLoop
        $Result &= $h_item0 &": " &$text &@LF
        $ItemID[$level] &= $h_item0 &";" &$pos &";"
    WEnd
    SearchChilds($level)
    $level +=+1
    SearchChilds($level)
    msgbox(0,"",$result)
Endfunc   

Func SearchChilds($level)
;msgBox(0,$level,$ItemID[$level])
    $aItemID = StringSplit($ItemID[$level],";")
    $level +=+1
    for $i = 1 to $aItemID[0/2]-1;Go to Read Childs from level if there are any
        $h_item = number($aItemID[$i])
        if $h_item <= 0 then ExitLoop
        if GUICtrlSendMsg($treeview, $TVM_GETNEXTITEM, $TVGN_CHILD, $h_item) > 0 then 
            ReadChilds($h_item, $aItemID[$i+1], $level)
            $result &= $subResult
        endif
        $i +=+1
    next
    return $result
EndFunc 
    
Func ReadChilds($item, $ParentNO, $level)
    local $h_item1
    $pos=10
    $subresult = ""
    $h_item1 = GUICtrlSendMsg($treeview, $TVM_GETNEXTITEM, $TVGN_CHILD, $item)
    $text = $ParentNO&$pos& _TreeViewGetItemText($h_tree, $h_item1)
    $subResult = $h_item1 &":" &$text &@LF
    While 1
        $pos += +1
        $h_item1 = GUICtrlSendMsg($treeview, $TVM_GETNEXTITEM, $TVGN_NEXT, $h_item1)
        $text = $ParentNO&$pos& _TreeViewGetItemText($h_tree, $h_item1)
        If $h_item1 <= 0 Then ExitLoop
        $subResult &= $h_item1 &":" &$text &@LF
        $ItemID[$level] &= $h_item1 &";"&$ParentNO&$pos &";"
    WEnd
;msgBox(0,"",$SubResult)
  return $subResult
EndFunc
Edited by ReFran
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...