Jump to content

show/hide treview item


 Share

Recommended Posts

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 by ledigeine
Link to comment
Share on other sites

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

  • Moderators

ledigeine,

The only way I can make it work is to actually delete/recreate the TreeView item: :)

#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? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

  • Moderators

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
Next

The 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 by Melba23
Typo

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

ledigeine,

Glad you followed. :)

Then the section in the switch case part i have no idea

Want me to explain that as well? ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

ledigeine,

See how you get on! :D

; 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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 :D

Link to comment
Share on other sites

  • Moderators

ledigeine,

Oops! :o

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

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

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