pekster Posted December 12, 2007 Share Posted December 12, 2007 I want to control both the expansion and collapse of a TreeViewItem but am unable to get the collapsing part to work. Below is my concept code:#include <GUIConstantsEx.au3> GUICreate("Example", 300, 300) $treeview = GUICtrlCreateTreeView(0, 0, 300, 260) $item1 = GUICtrlCreateTreeViewItem("Item 1", $treeview) $item2 = GUICtrlCreateTreeViewItem("Item 2", $item1) $button_expand = GUICtrlCreateButton("Expand", 0, 280, 100, 20) $button_collapse = GUICtrlCreateButton("Collapse", 200, 280, 100, 20) GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $button_expand $state = GUICtrlRead($item1) $state = BitOR($GUI_EXPAND, $state);expand item1 GUICtrlSetState($item1, $state);set control state Case $button_collapse $state = GUICtrlRead($item1) $state = BitOR($GUI_EXPAND, $state);expand item1 $state = BitXOR($GUI_EXPAND, $state);invert expansion so it is unset GUICtrlSetState($item1, $state);set control state EndSwitch WEndThings to note:The BitOR() and BitXOR() on lines 22-23 are required because the expansion condition is not known prior to execution. This insures the $GUI_EXPAND bit is not set by first setting it and then XOR-ing that bit to make it 0.There is no explicit $GUI_COLLAPSE variable, so I assume it is collapsed by setting the $GUI_EXPAND bit to 0. I can't find documentation to this end, so if I have the wrong idea let me know what I should do instead. [font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes. Link to comment Share on other sites More sharing options...
Zedna Posted December 12, 2007 Share Posted December 12, 2007 (edited) AutoIt 3.2.10: ControlTreeView("Expand/Collapse", "item") Edited December 12, 2007 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
pekster Posted December 12, 2007 Author Share Posted December 12, 2007 Thanks, that's just what I was looking to do. In case someone finds it useful I have modified my above concept code to use this method to do what I want. I'd also encourage this to be used as an example in the AutoIt manual since one doesn't yet exist. Feel free to modify it or add comments as necessary to use it as an example. #include <GUIConstantsEx.au3> $GUI = GUICreate("TreeView Control Example", 300, 150) $treeview = GUICtrlCreateTreeView(0, 0, 150, 100) $item1 = GUICtrlCreateTreeViewItem("Item 1", $treeview) $item2 = GUICtrlCreateTreeViewItem("Item 2", $item1) $button_expand = GUICtrlCreateButton("Expand", 160, 0, 100, 20) $button_collapse = GUICtrlCreateButton("Collapse", 160, 40, 100, 20) GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $button_expand ControLTreeView($GUI, "", $treeview, "Expand", "Item 1") Case $button_collapse ControLTreeView($GUI, "", $treeview, "Collapse", "Item 1") EndSwitch WEnd As the author of this code I hereby release it into the public domain for any purpose including alteration and re-distribution. [font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now