Jump to content

Use Array For GUICtrlSetState


Hobbyist
 Share

Recommended Posts

A newbie question, after browsing the forum (very newbie).  Is it possible to utilize an array to assign "state" when using GuiCtrlSetState?

If I create, say, 12 Listviews and 6 Buttons at startup BUT only want any one individual Listview to be viewed/enabled (at a time) and buttons as well, would it be better to use (if possible) an array to assign states based upon some button/listview relationship.  For example if Listview1 is viewed, all other Listviews would be hidden and or disabled.  So I could code it with the GuiCtrlSetState for each state per control and therefore have many such statements or put it into an array and call the state out based upon some button.  Would it work to concatenate the state from the array to the GuiCtrlSetState - GUICtrlSetState ( controlID, state ), so I would end up with

GuiCtrlSetState($List1, $myset), where $myset came from the array colum having "states". This would mean I would avoid having 11 GuiCtrlSetState($List(i), $GUI_HIDE) for each Listview viewed and so on for each state I might include.  I started down this path, see attached array, but not sure even if it is workable.  The other option I thought of was just delete each listview when it is not needed for viewing and create it when needed.

So the help i need is one of what makes sense and efficient and most important doable. What do the experienced people do (without making my head explode - HA!) I just included the array to give an idea of what I was attempting.

Thank you and if I have not been clear, tell me and I will attempt again.  

Hobbyist

#include <Array.au3>


local $matrix [7] [18] = [ [ 0,"$List1","$List2","$List3","$List4","$List5","$List6", "$List7" ,"$List8", "$List9" , _
"$List12" ,  "$List13","$List100",  "$Button4", "$Button12" ,  "$Button13", "$Button14", "$Button15"] , _
["Hide",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] ,  ["Show",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], _
["Enable",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] ,   ["Disable",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], ["Checked",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], _
   ["Unchecked",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]

_ArrayDisplay($matrix)

 

Link to comment
Share on other sites

What have you tried?

Why are you trying to have 12 listviews and only show one? Why not one and just clear it and fill it as you change the combination of the buttons?

You should post some code so we could help you better. We don't know what the buttons do to change the list views, what combination does what, or what's in the list views.

Link to comment
Share on other sites

Thank you for a response.

To your first question, the posted code on the array is all I have at this time.  This is currently an idea and I needed to get advice on what i will refer to as design.  In this case, would I be able to call "state" from an array. No sense in starting any coding if I don't have things properly mapped out before hand.  Additionally to design, does the array (as referred to above) make sense over just deleting the controls and recreating them if called upon later. I thought the experience on the forum would be of value in that regard. Second, the Listviews would have different data loaded from different files and differnt format. 

Any way, what I have found by LOTS of reading I can populate the array with  $matrix[4][0] =$GUI_DISABLE for instance and call it back to GUICtrlSetState ( controlID, state ), but it doesn't work to concatenate strings (or at least I may have done it wrong).

Again thank you.

Hobbyist

Link to comment
Share on other sites

There may be a simpler way to tackle what you want to do.  I personally don't see the value of having an array to track all of the possible states a control may be, particularly because some of the conditions are mutually exclusive (you can't be both Show/Hidden, Enabled/Disabled, Checked/Unchecked).  Also, there is nothing that enforces the values/states in the array to actually match the values/states of the controls.  For instance, you could accidentally set the wrong array subscript or value if there is a coding mistake.  I usually prefer to tell the controls what I want them to do/be and ask them what they are when I need to, rather than track a previously "known" state...unless you need some "undo" functionality or need to address a specific performance issue.  I'm no expert, so take my input for what it's worth.  You are definitely on the right track using an array to do a series of control updates/changes.  

Edited by spudw2k
Link to comment
Share on other sites

Hobbyist,

6 hours ago, Hobbyist said:

but it doesn't work to concatenate strings

If you want to set a value of multiple states for a control (e.g. enabled and checked)...

Quote

State values can be summed up as for example $GUI_DISABLE (128) + $GUI_HIDE (32) sets the control in an disabled and hidden state.

(see GuiCtrlSetState)

 Is this what you are asking?

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

@ kylomas

Thank you for responding.  I MISSED the section (while reading) about the summation and can see its usefulness (instead of two or more SetState lines I can get the same result using one with summation).

I was also seeking advice regarding multiple control states.  For instance if I had 12 Listviews (each being different in format and content) and wanted to only allow ONE Listview to be shown at a time I would potentially have  11 GuiCtrlSetState  - GUICtrlSetState($Listchoice ,$GUI_hide) statement, one for each Listview not to be seen. Now 11 since I know summation works, otherwise 22 -one for hide/one for disable.  Plus if I have any other controls specific to a particular LIstview I would have to do the same for them.  Thats why I was thinking of an array grid perhaps that I could populate with 1's and 0's to signify a state based upon associated buttons or menu controls. i would have to start with a default of some sort and then allow for the navigation as desired.  So if List1 was default, all others hidden and as soon as another choice is made one of the others is visible and List1 becomes hidden. All this means I create all Listviews at start time.

Alternatively I thought perhaps it more feasible to just delete a particular control any time it is not visible and create it each time an associated button or menu control is used. I don't have enough experience or knowledge of the subject to say which would be better from a resource standpoint or even if it matters.  

I didn't code any of the Listviews or Guis at this point because no point to design unless I know which way to go or if my idea is even possible.  So its an array or no array question or the deletion process.

 

Thanks

Hobbyist

 

 

 

Link to comment
Share on other sites

Kylomas

Here is something I threw together (its not pretty, 'eh).  I have the array displaying throughout to show what I was doing -

labeling and updating.

Clicking the Matrix button should create and display the Listviews and they overlap so to see the title.

After the function is complete in the Matrix button, I have a MSG Box just to stop things as the code following the MSG Box is aproblem and I am sure I don't have it right and I know it does NOT go there but should be up in the Swith and problably as some Win Focus(don't know).

The concept would be to focus on any Listview and then in this case ANY Listview not focused would be hidden/disabled thus only one is viewable/enabled. I would guess I should think of a reset button to bring them all back viewable but haven't got that far with the current problem.

Thanks so much for your time.

Hobbyist

#include <Array.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <ColorConstants.au3>
#include <ComboConstants.au3>
#include <Date.au3>
#include <EditConstants.au3>
#include <File.au3>
#include <GUIComboBox.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <Misc.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
#include <String.au3>
#include <WindowsConstants.au3>
#include <StringConstants.au3>
#include <FileConstants.au3>
#include <GuiTab.au3>
#include <GuiButton.au3>
#include <GuiMenu.au3>
#include <WinAPI.au3>
#include <Constants.au3>
#include <WinAPIFiles.au3>
#include <GuiDateTimePicker.au3>
#include <Sound.au3>
#include <GuiScrollBars.au3>


;I know I don't need all the above, its just a template that I throw everything into so I can move along each time
;Looking to create seris of Listviews but ONLY ONE is viewable at a time
;thought the array would be the place to store the needed data to CHANGE STATE depending upon any button I would put on it.

global $ListAll
local $matrix [8] [18] = [ [ 0,"$List1","$List2","$List3","$List4","$List5","$List6", "$List7" ,"$List8", "$List9" , _
"$List12" ,  "$List13","$List100",  "$Button4", "$Button12" ,  "$Button13", "$Button14", "$Button15"] , _
["Hide",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] ,  ["Show",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], _
["Enable",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] ,   ["disABLE",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], ["Checked",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], _
   ["Unchecked",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],   ["ControlID",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]                                            ]
_ArrayDisplay($matrix, "LABELS")

;update for state in column 0
$matrix [1] [0] = $GUI_HIDE
$matrix [2] [0] = $GUI_SHOW
$matrix [3] [0] = $GUI_ENABLE
$matrix[4][0] =$GUI_DISABLE
$matrix [5] [0] = $GUI_CHECKED
$matrix [6] [0] = $GUI_UNCHECKED
_ArrayDisplay($matrix, "Update It") ; updated

$main = GUICreate("Dash Board", 680, 515, 150, 100) ;height was 480

$Button14 = GUICtrlCreateButton("Matrix", 10, 140, 120, 33)
GUICtrlSetState($Button14,$GUI_enABLE)
GUICtrlSetState($Button14,$GUI_show)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetBkColor(-1, 0xE3E3E3)


GUISetState(@SW_SHOW)

GUISetState()

While 1

        $iMsg = GUIGetMsg()
         Switch $iMsg

                    Case $GUI_EVENT_CLOSE

                 Exit

            case $Button14
                _SeeAll() ;create all Listviews and show


         EndSwitch

WEnd

Func _SeeAll()
    $j = 40
    For $i = 1 to 12
$ListAll = (    $ListAll&$i )
$ListAll =  GUICtrlCreateListview("List"&$i,  154, $j,500, 200 )

_GUICtrlListView_SetExtendedListViewStyle ( $ListAll,BitOR( $LVS_EX_HEADERDRAGDROP, $LVS_EX_GRIDLINES))
_GUICtrlListView_AddColumn( $ListAll, "A", 70)
_GUICtrlListView_AddColumn( $ListAll, "B", 70)
_GUICtrlListView_AddColumn( $ListAll, "C", 70)
_GUICtrlListView_AddColumn( $ListAll, "D", 70)
_GUICtrlListView_AddColumn( $ListAll, "E", 70)
_GUICtrlListView_AddColumn( $ListAll, "F", 70)
 GUICtrlSetFont(-1, 8.5, 700, 0, "MS Ariel")
GUICtrlSetBkColor( $ListAll, $COLOR_aqua)
GUICtrlSetFont(-1, 8.5, 700, 0, "MS Ariel")
GUICtrlSetState( $ListAll,$matrix[2][0]); show
GUICtrlSetState( $ListAll,$matrix[3][0]);enable
$matrix [2] [$i] = 1 ;assign 1 for any enabled and showing Listview
$matrix [3][$i] = 1  ;assign 1 for any enabled and showing Listview
$matrix [7][$i] =$ListAll ; controlID when creating?
$j = $j + 30 ;move each listview down to see each heading
next

;show array for all updates
_ArrayDisplay($matrix, "1 for created listview show/enable") ; indicator "1" for created listview

;just threw in MSG to stop and then click on any listview to FOCUS, HIDE any not having focus
;I know this is not where it goe, it should be in the switch above - not sure HOW
MsgBox(64, "Status", "hide")
    For $i = 1 to 12
                If not Bitand(GUICtrlRead($matrix[7][$i]), $GUI_focus) = $GUI_focus  Then
                    GUICtrlSetState(($matrix [7][$i]),$GUI_hide)
                EndIf
                Next

    EndFunc

 

Link to comment
Share on other sites

I have changed/updated this script.

I am seeking to create multiple Listviews (in this case 12), which the script does. There may be a better way to do this, but I don't know what it is. Second to this, I am seeking to 1.) be able to click on any ONE of the Listviews and that action ALSO hides the other Listview, leaving only the one desired to be viewed.

I have attempted to use _WinAPI_GetFocus() in a swith to accomplish the second part of what I am doing. Needless to say it does not work, so I am looking for some guidance on this solution.  Along with that, i will be attempting to reset all the Listviews after viewing the original selection mentioned above.

 

Any help would be appreciated.

Hobbyist

#include <Array.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <ColorConstants.au3>
#include <ComboConstants.au3>
#include <Date.au3>
#include <EditConstants.au3>
#include <File.au3>
#include <GUIComboBox.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <Misc.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
#include <String.au3>
#include <WindowsConstants.au3>
#include <StringConstants.au3>
#include <FileConstants.au3>
#include <GuiTab.au3>
#include <GuiButton.au3>
#include <GuiMenu.au3>
#include <WinAPI.au3>
#include <Constants.au3>
#include <WinAPIFiles.au3>
#include <GuiDateTimePicker.au3>
#include <Sound.au3>
#include <GuiScrollBars.au3>


;I know I don't need all the above, its just a template that I throw everything into so I can move along each time
;Looking to create seris of Listviews but ONLY ONE is viewable at a time
;thought the array would be the place to store the needed data to CHANGE STATE depending upon any button I would put on it.

global $ListAll[20] [2]
local $matrix [8] [18] = [ [ 0,"$List1","$List2","$List3","$List4","$List5","$List6", "$List7" ,"$List8", "$List9" , _
"$List12" ,  "$List13","$List100",  "$Button4", "$Button12" ,  "$Button13", "$Button14", "$Button15"] , _
["Hide",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] ,  ["Show",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], _
["Enable",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] ,   ["disABLE",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], ["Checked",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], _
   ["Unchecked",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],   ["ControlID",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]                                            ]
;_ArrayDisplay($matrix, "LABELS")

;update for state in column 0
$matrix [1] [0] = $GUI_HIDE
$matrix [2] [0] = $GUI_SHOW
$matrix [3] [0] = $GUI_ENABLE
$matrix[4][0] =$GUI_DISABLE
$matrix [5] [0] = $GUI_CHECKED
$matrix [6] [0] = $GUI_UNCHECKED
;_ArrayDisplay($matrix, "Update It") ; updated

$main = GUICreate("Dash Board", 680, 515, 150, 100) ;height was 480

$Button14 = GUICtrlCreateButton("Matrix", 10, 140, 120, 33)
GUICtrlSetState($Button14,$GUI_enABLE)
GUICtrlSetState($Button14,$GUI_show)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetBkColor(-1, 0xE3E3E3)
GUICtrlSetState($Button14, $GUI_FOCUS)

GUISetState(@SW_SHOW)

GUISetState()

While 1

        $iMsg = GUIGetMsg()
         Switch $iMsg

                    Case $GUI_EVENT_CLOSE

                 Exit

            case $Button14
                _SeeAll() ;create all Listviews and show
                

            Switch _WinAPI_GetFocus() ;; Looking to do this - click on ANY displayed Listview and that causes balance of listviews to HIDE

                                Case    $ListAll[1] [1] to  $ListAll[12] [1] ;handles of all listviews in array
                                    for $i = 1 to 12

                        If Not BitAnd(GUICtrlGetState( $ListAll[$i] [0] ), $GUI_focus) = $GUI_focus Then GUICtrlSetState( $ListAll[$i] [0], $GUI_hide)
                                    Next

                    EndSwitch

     EndSwitch


WEnd

Func _SeeAll()
    $j = 40
    For $i = 1 to 12

$ListAll[$i][0] =  GUICtrlCreateListview("$ListAll"&$i,  154, $j,500, 200 );$LVS_EX_HEADERDRAGDROP;,$LVS_SINGLESEL, $LVS_EX_GRIDLINES + $LVS_EX_FULLROWSELECT)
 $ListAll[$i] [1]=   GUICtrlGetHandle ($ListAll[$i][0]  )

_GUICtrlListView_SetExtendedListViewStyle ( $ListAll,BitOR( $LVS_EX_HEADERDRAGDROP, $LVS_EX_GRIDLINES))
_GUICtrlListView_AddColumn( $ListAll[$i][0] , "A", 70)
_GUICtrlListView_AddColumn( $ListAll[$i][0] , "B", 70)
_GUICtrlListView_AddColumn( $ListAll[$i][0] , "C", 70)
_GUICtrlListView_AddColumn( $ListAll[$i][0] , "D", 70)
_GUICtrlListView_AddColumn( $ListAll[$i][0] , "E", 70)
_GUICtrlListView_AddColumn( $ListAll[$i][0] , "F", 70)
 GUICtrlSetFont(-1, 8.5, 700, 0, "MS Ariel")
GUICtrlSetBkColor( $ListAll[$i][0] , $COLOR_aqua)
GUICtrlSetFont(-1, 8.5, 700, 0, "MS Ariel")
GUICtrlSetState( $ListAll[$i][0] ,$matrix[2][0]);
GUICtrlSetState( $ListAll[$i][0] ,$matrix[3][0])
$matrix [2] [$i] = 1
$matrix [3][$i] = 1

$j = $j + 30
next

_ArrayDisplay($ListAll, " listview array") ; controlID column 0, handle column 1
EndFunc

 

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