Jump to content

TreeViewItem Questions


 Share

Recommended Posts

The following code tracks the state of a treeviewItem.

I try to detect when a treeviewitem is expanded, or how to make it invisible

The following script shows that its state (GuiCtrlRead) does not reflect both 'expand' nor 'hide' states.

Whereas the state 'selected' is detected both by the OnEvent function attached to the treeviewitem, and by the GuiCtrlRead() function...

Is there a way to read those states 'expand' and 'hide'?

(I suspect that to make a treeviewitem invisible,... the surest way is to delete it! But I want to ask first is there is any other way)

#include "GUIConstants.au3"
Opt ("GUIOnEventMode", 1); Allow for OnEvent mode notification
$title = "test Treeview"
$gui = GUICreate($title, 200, 200, -1, -1, $WS_SIZEBOX)
GUISetOnEvent($GUI_EVENT_CLOSE,"_Exit",$gui)

$buttonInvisible = GUICtrlCreateButton("Main Invisible", 20,10,80,20)
GUICtrlSetOnEvent($buttonInvisible, "_setMainItemInvisible")
GUICtrlSetResizing($buttonInvisible,$GUI_DOCKALL)
$buttonExpand = GUICtrlCreateButton("Main Expand", 110,10,80,20)
GUICtrlSetOnEvent($buttonExpand, "_setMainItemExpanded")
GUICtrlSetResizing($buttonExpand,BitOR($GUI_DOCKTOP,$GUI_DOCKSIZE,$GUI_DOCKRIGHT))

$treeview = GUICtrlCreateTreeView(0,40,210,160)
GUICtrlSetResizing($treeview,$GUI_DOCKBORDERS)

$mainitem = GUICtrlCreateTreeViewItem("Main", $treeview)
GUICtrlSetOnEvent($mainitem, "_actionOnItem")
$subitem = GUICtrlCreateTreeViewItem("SubItem", $mainitem)

GUISetState(@SW_SHOW, $gui)
$nb = 0
_consoleWritePosSubItem()

$state = -1
while 1
    Sleep(10)
    $newstate = GUICtrlRead($mainitem)
    if $newstate <> $state Then
        $state = $newstate
        GUICtrlSetData($mainitem,"Main, state '"&$state&"'")
        _consoleWritePosSubItem()
    EndIf
WEnd

Func _consoleWritePosSubItem()
    $nb = $nb + 1
    $pos = ControlGetPos($title,"",$subitem)
    if @error == 0 Then
        ConsoleWrite($nb &"POS: " & $pos[0] & "," & $pos[1] & " SIZE: " & $pos[2] & "," & $pos[3] )
    Else
        ConsoleWrite($nb &"POS UNAVAILABLE")        
    EndIf
    ConsoleWrite(@LF)
EndFunc

Func _setMainItemInvisible()
    GUICtrlSetState($mainitem,$GUI_HIDE)
EndFunc
    
Func _setMainItemExpanded()
    GUICtrlSetState($mainitem,$GUI_EXPAND)
EndFunc

Func _actionOnItem()
    $newstate = GUICtrlRead($mainitem)
    if $newstate <> $state Then
        $state = $newstate
    EndIf
    GUICtrlSetData($mainitem,"Main, state '"&$state&"', activated")
    Sleep(500)
    GUICtrlSetData($mainitem,"Main, state '"&$state&"'")
    _consoleWritePosSubItem()
EndFunc

Func _Exit()
    Exit
EndFunc
Edited by vonc

-- VonCMinefield

Link to comment
Share on other sites

Argh... :(

I try to update the script in the previous message, displaying the position (ControlGetPos) of the sub item (TreeViewItem)

The idea is: if the parent item is not expanded, the position of its subitem would be "unavailable", if the parent is expanded, the subitem would have a "position"

But that position seems to be unavailable, whether the subitem is visible (parent expanded) or not...

That is not all that surprising: a TreeViewItem must be a particular brand of control: only the TreeView is the official visible (with a position) control.

So that gets me back to square 1:

- How do I detect that a TreeViewItem is expanded or not ?

- How do I make a TreeViewItem invisible ?

-- VonCMinefield

Link to comment
Share on other sites

Argh... :(

I try to update the script in the previous message, displaying the position (ControlGetPos) of the sub item (TreeViewItem)

The idea is: if the parent item is not expanded, the position of its subitem would be "unavailable", if the parent is expanded, the subitem would have a "position"

But that position seems to be unavailable, whether the subitem is visible (parent expanded) or not...

That is not all that surprising: a TreeViewItem must be a particular brand of control: only the TreeView is the official visible (with a position) control.

So that gets me back to square 1:

- How do I detect that a TreeViewItem is expanded or not ?

- How do I make a TreeViewItem invisible ?

<{POST_SNAPBACK}>

I hope Holger can see your post so you can have a very precise answer

but doc say

To expand a treeview item just use GuiCtrlSetState($treeviewItem, $GUI_EXPAND).

so that's part of the answer.
Link to comment
Share on other sites

Hi Jpm,

Thanks for the answer

I known indeed how to expand a node.

What I do not know is, for a given node (treeviewitem), how to detect that this node is or is not expanded...

Thank you in advance.

--

VonC

-- VonCMinefield

Link to comment
Share on other sites

Hi vonc :(

I will try to put the expanded-state-info into GUICtrlRead cause checked/unchecked-state of treeviewitems is already in.

I will check it outthe next days...

!But to set an item (in)visible is not possible!

Regards

Holger

Link to comment
Share on other sites

Hi Holger,

Thank you for your upcoming update! :(

What is frustrating in a more general way is that :

- you can set various state on a given control (like GuiCtrlSetState($treeviewItem, $GUI_EXPAND), as mentionned by Jpm)

- and yet GUICtrlRead() does not reflect that state.

In this thread, you (Holger) suggested to use:

If BitAnd(GUICtrlRead(treeviewitemID),$GUI_CHECKED) Then; item is checked

Well, my dream would be to be able to use:

If BitAnd(GUICtrlRead(treeviewitemID),$GUI_EXPAND) Then; item is expanded

(I know, weird dream huh ? :( ) Edited by vonc

-- VonCMinefield

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