Jump to content

Treeview and GUICtrlSetOnEvent


PaulDG
 Share

Recommended Posts

Is there anyway to define a GUICtrlSetOnEvent to trigger on any treeview action?

I am using on even mode and would like to execute a function on any treeview focus, not checkboxes but focus IE When i click on the item or subitem.

I have searched for ages and come up with nothing. But i could be blinded by the trees...

Thanks

Link to comment
Share on other sites

here's an example converted to events

#include <GUIConstants.au3>
Opt("GUIOnEventMode",1)
GUICreate("My GUI with treeview",350,212)

$treeview = GUICtrlCreateTreeView (6,6,100,150,BitOr($TVS_HASBUTTONS,$TVS_HASLINES,$TVS_LINESATROOT,$TVS_DISABLEDRAGDROP,$TVS_SHOWSELALWAYS),$WS_EX_CLIENTEDGE)
$generalitem = GUICtrlCreateTreeViewitem ("General",$treeview)
GUICtrlSetOnEvent($generalitem,"_ItemsSelected")
$displayitem = GUICtrlCreateTreeViewitem ("Display",$treeview)
GUICtrlSetOnEvent($displayitem,"_ItemsSelected")
$aboutitem = GUICtrlCreateTreeViewitem ("About",$generalitem)
GUICtrlSetOnEvent($aboutitem,"_ItemsSelected")
$compitem = GUICtrlCreateTreeViewitem ("Computer",$generalitem)
GUICtrlSetOnEvent($compitem,"_ItemsSelected")
$useritem = GUICtrlCreateTreeViewitem ("User",$generalitem)
GUICtrlSetOnEvent($useritem,"_ItemsSelected")
$resitem = GUICtrlCreateTreeViewitem ("Resolution",$displayitem)
GUICtrlSetOnEvent($resitem,"_ItemsSelected")
$otheritem = GUICtrlCreateTreeViewitem ("Other",$displayitem)
GUICtrlSetOnEvent($otheritem,"_ItemsSelected")

$startlabel = GUICtrlCreateLabel ("TreeView Demo",190,90,100,20)
$aboutlabel = GUICtrlCreateLabel ("This little scripts demonstates the using of a treeview-control.",190,70,100,60)
GUICtrlSetState(-1,$GUI_HIDE)
$compinfo = GUICtrlCreateLabel ("Name:" & @TAB & @ComputerName & @LF & "OS:" & @TAB & @OSVersion & @LF & "SP:" & @TAB & @OSServicePack,120,30,200,80)
GUICtrlSetState(-1,$GUI_HIDE)

$okbutton = GUICtrlCreateButton ("OK",100,185,70,20)
$cancelbutton = GUICtrlCreateButton ("Cancel",180,185,70,20)
GUICtrlSetOnEvent($cancelbutton,"_Exit")

GUISetState ()
While 1
    Sleep ( 250 )
WEnd

GUIDelete()
Exit

Func _ItemsSelected()
    Select
        Case @GUI_CtrlId = $generalitem
            GUIChangeItems($aboutlabel,$compinfo,$startlabel,$startlabel)
        
        Case @GUI_CtrlId = $aboutitem
            GUICtrlSetState ($compinfo,$GUI_HIDE)
            GUIChangeItems($startlabel,$startlabel,$aboutlabel,$aboutlabel)
            
        Case @GUI_CtrlId = $compitem
            GUIChangeItems($startlabel,$aboutlabel,$compinfo,$compinfo)
    EndSelect
EndFunc

Func _Exit()
 Exit
EndFunc

Func GUIChangeItems($hidestart,$hideend,$showstart,$showend)
    Local $idx
    
    For $idx = $hidestart To $hideend
        GUICtrlSetState ($idx,$GUI_HIDE)
    Next
    For $idx = $showstart To $showend
        GUICtrlSetState ($idx,$GUI_SHOW)
    Next    
EndFunc

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

So for every treeviewitem i have to set an onevent as well, Thats gonna mean 60 to 100 onevents. I hope that wont be an issue.

Its a shame we cant set an onevent on the parent treeview, it would save alot of code and probably memory.

Oh well, Thanks for the example.

Link to comment
Share on other sites

So for every treeviewitem i have to set an onevent as well, Thats gonna mean 60 to 100 onevents. I hope that wont be an issue.

Its a shame we cant set an onevent on the parent treeview, it would save alot of code and probably memory.

Oh well, Thanks for the example.

I tried on event on the treeview itself, but didn't work, but here's a twist to the previous example:

#include <GUIConstants.au3>
opt("GUIOnEventMode", 1)
GUICreate("My GUI with treeview", 350, 212)
Local $a_ids[7]
$treeview = GUICtrlCreateTreeView(6, 6, 100, 150, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
$a_ids[0] = GUICtrlCreateTreeViewItem("General", $treeview)
$a_ids[1] = GUICtrlCreateTreeViewItem("Display", $treeview)
$a_ids[2] = GUICtrlCreateTreeViewItem("About", $a_ids[0])
$a_ids[3] = GUICtrlCreateTreeViewItem("Computer", $a_ids[0])
$a_ids[4] = GUICtrlCreateTreeViewItem("User", $a_ids[0])
$a_ids[5] = GUICtrlCreateTreeViewItem("Resolution", $a_ids[1])
$a_ids[6] = GUICtrlCreateTreeViewItem("Other", $a_ids[1])

For $x = 0 To UBound($a_ids) - 1
    GUICtrlSetOnEvent($a_ids[$x], "_ItemsSelected")
Next

$startlabel = GUICtrlCreateLabel("TreeView Demo", 190, 90, 100, 20)
$aboutlabel = GUICtrlCreateLabel("This little scripts demonstates the using of a treeview-control.", 190, 70, 100, 60)
GUICtrlSetState(-1, $GUI_HIDE)
$compinfo = GUICtrlCreateLabel("Name:" & @TAB & @ComputerName & @LF & "OS:" & @TAB & @OSVersion & @LF & "SP:" & @TAB & @OSServicePack, 120, 30, 200, 80)
GUICtrlSetState(-1, $GUI_HIDE)

$okbutton = GUICtrlCreateButton("OK", 100, 185, 70, 20)
$cancelbutton = GUICtrlCreateButton("Cancel", 180, 185, 70, 20)
GUICtrlSetOnEvent($cancelbutton, "_Exit")

GUISetState()
While 1
    Sleep(250)
WEnd

GUIDelete()
Exit

Func _ItemsSelected()
    For $x = 0 To UBound($a_ids) - 1
        If BitAND($GUI_FOCUS, GUICtrlRead($a_ids[$x]), $GUI_FOCUS) Then
            $tmp = GUICtrlRead($a_ids[$x], 1)
            If $x = 0 Then
                GUIChangeItems($aboutlabel, $compinfo, $startlabel, $startlabel)
            ElseIf $x = 2 Then
                GUICtrlSetState($compinfo, $GUI_HIDE)
                GUIChangeItems($startlabel, $startlabel, $aboutlabel, $aboutlabel)
            ElseIf $x = 3 Then
                GUIChangeItems($startlabel, $aboutlabel, $compinfo, $compinfo)
            EndIf
        EndIf
    Next
EndFunc  ;==>_ItemsSelected

Func _Exit()
    Exit
EndFunc  ;==>_Exit

Func GUIChangeItems($hidestart, $hideend, $showstart, $showend)
    Local $idx
    
    For $idx = $hidestart To $hideend
        GUICtrlSetState($idx, $GUI_HIDE)
    Next
    For $idx = $showstart To $showend
        GUICtrlSetState($idx, $GUI_SHOW)
    Next
EndFunc  ;==>GUIChangeItems
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...