ledigeine Posted August 8, 2012 Share Posted August 8, 2012 (edited) Ok I found in the helpfile a example script that has a GUI and a view menu, you can check or uncheck the item in view and it will make something show or hide on the ui. So on a UI i have there is a treeview with 4 items as the starting branches. All i need is the view menu up top have those 4 treeview items listed with a check mark by default. I have that so far, when unchecking the first item it will uncheck from the view menu but it will not hide the treeview item. So all 4 items are still listed. I am thinking I need to refresh the tree view once an item in the view menu has been clicked? I just dont see that in the example code i got form the help file. Edit: In this case $testassV the variable for the item in the view menu. $ass is the variable for the item in the treeview i am trying to show/hide. Case $testassV If BitAND(GUICtrlRead($testassV), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($testassV, $GUI_UNCHECKED) GUICtrlSetState($ass, $GUI_HIDE) Else GUICtrlSetState($testassV, $GUI_CHECKED) GUICtrlSetState($ass, $GUI_SHOW) EndIf Edited August 8, 2012 by ledigeine Link to comment Share on other sites More sharing options...
ledigeine Posted August 8, 2012 Author Share Posted August 8, 2012 Looking at it more it might not be possible to hide treeviewitems I might need to not list the items right off then alter the list based on what is chosen in the view menu. Maybe build the list based on the view menu from the start, then if the view menu is used refresh the screen some how to show/hide what should be shown/hidden. Then i will have to store what the user has chosen in some xml file so the changes do not reset each time they use this little utility. Any ideas are welcome still incase i am wrong. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 8, 2012 Moderators Share Posted August 8, 2012 ledigeine, The only way I can make it work is to actually delete/recreate the TreeView item: expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiTreeView.au3> Global $aItem[4], $aMenu[4] $hGUI = GUICreate("Test", 500, 500) GUISetBkColor(0xC4C4C4) $mView = GUICtrlCreateMenu("View") For $i = 0 To 3 $aMenu[$i] = GUICtrlCreateMenuItem("Item " & $i, $mView) GUICtrlSetState(-1, $GUI_CHECKED) Next $cTV = GUICtrlCreateTreeView(250, 10, 200, 200) For $i = 0 To 3 $aItem[$i] = GUICtrlCreateTreeViewItem("Item " & $i, $cTV) Next GUISetState() While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $aMenu[0] To $aItem[3] For $i = 0 To 3 If $iMsg = $aMenu[$i] Then If BitAND(GUICtrlRead($aMenu[$i]), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($aMenu[$i], $GUI_UNCHECKED) _GUICtrlTreeView_Delete($cTV, $aItem[$i]) $aItem[0] = 0 Else GUICtrlSetState($aMenu[$i], $GUI_CHECKED) $aItem[$i] = GUICtrlCreateTreeViewItem("Item " & $i, $cTV) _GUICtrlTreeView_Sort($cTV) EndIf EndIf Next EndSwitch WEnd Any use? M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
ledigeine Posted August 8, 2012 Author Share Posted August 8, 2012 Running yours real quick its exactly what i need... just I don't really understand these For Next things. Say with the first fornext, for when $i is between 0 and 3 it will do whats inside the for and next? So $i is 0 now, it runs the creation of the item and sets it to checked in the menu. Then runs it again $i being 1 this time, it does that until $i is 3 then goes creates the treeview and all that. Correct? Then the section in the switch case part i have no idea. haha Right when I start to think I'm learning i see a bunch of stuff i have no idea whats going on. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 8, 2012 Moderators Share Posted August 8, 2012 (edited) ledigeine,Not quite. In a For...Next loop, the loop variable ($i in this case) is set to the values assigned in the For line:For $i = 0 To 3 1st pass $i = 0 2nd pass $i = 1 3rd pass $i = 2 4th pass $i = 3 NextThe 4th time we reach Next, $i will = 4. This is above the top limit set initially and so the loop ends.The next time we start a loop, $i resets to whatever start value is set - in the case of the script above, it resets to 0.All clear so far? M23 Edited August 8, 2012 by Melba23 Typo ledigeine 1  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
ledigeine Posted August 8, 2012 Author Share Posted August 8, 2012 Very nice, i was wondering with how i thought it worked... how would $i ever change values. Now i get that part of it. Thank you for that! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 8, 2012 Moderators Share Posted August 8, 2012 ledigeine,Glad you followed. Then the section in the switch case part i have no ideaWant me to explain that as well? M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
ledigeine Posted August 8, 2012 Author Share Posted August 8, 2012 That would be simply wonderful, although i cant promise i will follow as easily Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 8, 2012 Moderators Share Posted August 8, 2012 ledigeine, See how you get on! ; Get the event message $iMsg = GUIGetMsg() ; And run it through the Switch Switch $iMsg ; Self-evident Case $GUI_EVENT_CLOSE Exit ; Because we created the menu items in immediate succession they have consecutive ControlIDs so we look for a range Case $aMenu[0] To $aItem[3] ; It was one of them so we loop through the array holding the ControlIDs to find out which one For $i = 0 To 3 If $iMsg = $aMenu[$i] Then ; It was this one - and $i is set to the correct number automatically ; Now we set things as we want If BitAND(GUICtrlRead($aMenu[$i]), $GUI_CHECKED) = $GUI_CHECKED Then ; We uncheck the menu GUICtrlSetState($aMenu[$i], $GUI_UNCHECKED) ; Delete the TV item _GUICtrlTreeView_Delete($cTV, $aItem[$i]) ; Clear the ControlID from the array - not strictly necessary but good practice $aItem[0] = 0 Else ; Tick the menu GUICtrlSetState($aMenu[$i], $GUI_CHECKED) ; Recreate the TY item and insert the ControlID into the array $aItem[$i] = GUICtrlCreateTreeViewItem("Item " & $i, $cTV) ; Again not strictly necessary but it restores the same order as before _GUICtrlTreeView_Sort($cTV) EndIf ; I should have added this the first time - if we find a match there is no use looking for another ; So we leave the For...Next loop and look for the next event ExitLoop EndIf Next EndSwitch The magic is using the same index for both arrays - then when we find out which menu item was clicked we automatically know which TV item to deal with. Please ask if anything is still unclear. M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
ledigeine Posted August 9, 2012 Author Share Posted August 9, 2012 Hmm after looking it over i think I get the whole idea now, but a specific part i dont really understand is this one.Case $aMenu[0] To $aItem[3] i feel like we would be comparing $aMenu[0] to $aItem[0] but maybe you are meaning a range... it still confuses me a bit Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 9, 2012 Moderators Share Posted August 9, 2012 ledigeine,Oops! It should read:Case $aMenu[0] To $aMenu[3]as we are trying to trap the event associated with menu selections and that array holds the ControlIDs of the items within it. As the items were created in immediate succession the ControlIDs are successive integers and so we can use a range to detect them. M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
ledigeine Posted August 9, 2012 Author Share Posted August 9, 2012 OMG i actually was slightly right! Ok yeah that part tripped me up a bit. So would it matter how i setup the menu and list items? I mean right now i have the menu setup with each item checked. Then the treeview auto loads with all of the items there. In the long run id wana have a xml that holds the users settings... but for now checking the options and making them in the list view should be good to start i believe. Link to comment Share on other sites More sharing options...
ledigeine Posted August 10, 2012 Author Share Posted August 10, 2012 Ok i put all this to use, well some of it i couldnt really use the very cool array part because my items are not so similar. But I am using the section in the while. Its working great.... expect me to be posting again soon ha. I have to now somehow store how the items are set in my VIEW menu so when they close the application and open it again everything is saved. I plan to throw those settings in an xml since im already using one for another section. 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