Jewtus

GUI driven based on listview

3 posts in this topic

#1 ·  Posted (edited)

I have been trying to figure out how to get my GUI to do what I want. I am including sample code below that has what I'm working with.

 

Essentially, what I want is for 4 list views to control the visibility and the ability to change data on a sub GUI. The primary gui has the 4 list views and a tab control (as well as 3 tabs). I want to be able to click on the first list view and have it activate the first tab and allow the values to be changed (the example only has a label). When the 2nd list view is clicked, I want it to disable the first tab and enable the 2nd tab for editing. When the 3rd list view is clicked, I want the 3rd tab to be activated and editable, and when the 4th list view is clicked, I want all tabs to be visible but not editable. Preferably, I'd like to have the 2nd and 3rd tab hidden if the first list view is selected, but I'll settle for it just being disabled.

 

Can anyone point out what I'm doing wrong? The disable commands I have before any of the case statements don't seem to do anything and I'm struggling to figure out how to tweak this to achieve what I'm looking for.

 

Here is my code:

#include <WindowsConstants.au3> ; $WS_Maximizebox
#include <GUICombobox.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>

Entry()

Func Entry()
    Local $riskID
    Global $aGUIChildren[3], $labArea[3]
    Global $RiskGUI = GUICreate("Entry", 960, 500)
    GUICtrlSetFont(-1, 20, 400, 0, "Times New Roman")
$iStart = GUICtrlCreateDummy()
    global $idRisksFirst = GUICtrlCreateListView("", 16, 48, 161, 97)
    global $idRisksSecond = GUICtrlCreateListView("", 16, 152, 161, 97)
    global $idRisksThird = GUICtrlCreateListView("", 16, 256, 161, 97)
    global $idRisksFinal = GUICtrlCreateListView("", 16, 360, 161, 97)
$iEnd = GUICtrlCreateDummy()
    local $testVals[3][3]=[[1,2,3],[1,2,3],[1,2,3]]
    For $i = $iStart To $iEnd
        _GUICtrlListView_AddColumn($i,"ID",25)
        _GUICtrlListView_AddColumn($i,"Type",70)
        _GUICtrlListView_AddColumn($i,"Entered By",65)
    Next
    _GUICtrlListView_AddArray($idRisksFirst,$testVals)
    _GUICtrlListView_AddArray($idRisksSecond,$testVals)
    _GUICtrlListView_AddArray($idRisksThird,$testVals)
    _GUICtrlListView_AddArray($idRisksFinal,$testVals)
GUIRegisterMsg($WM_NOTIFY, "LV_NOTIFY")

    $newFirst = GUICtrlCreateButton("New", 183, 78, 27, 25)
    $newSecond = GUICtrlCreateButton("New", 183, 190, 27, 25)
    $btnRefresh = GUICtrlCreateButton("Refresh", 844, 96, 75, 25)

    Global $Tabs = GUICtrlCreateTab(216, 48, 577, 440)
    $tab1=GUICtrlCreateTabItem("First")
    GUICtrlSetState($tab1,$GUI_HIDE)
    $tab2=GUICtrlCreateTabItem("Second")
    GUICtrlSetState($tab2,$GUI_HIDE)
    $tab3=GUICtrlCreateTabItem("Final")
    GUICtrlSetState($tab3,$GUI_HIDE)
    $aGUIChildren[0]=SubGui($aGUIChildren,0,True)
    $aGUIChildren[1]=SubGui($aGUIChildren,1,True)
    $aGUIChildren[2]=SubGui($aGUIChildren,2,True)

    GUISetState(@SW_SHOW,$RiskGUI)
    GUISetState(@SW_SHOW,$aGUIChildren[0])
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete($RiskGUI)
                GUIDelete($aGUIChildren[0])
                GUIDelete($aGUIChildren[1])
                GUIDelete($aGUIChildren[2])
                ExitLoop
            Case $Tabs
                ; Hide/show children depending on tab selected
                For $i = 0 To 2
                    GUISetState(@SW_HIDE, $aGUIChildren[$i])
                Next
                GUISetState(@SW_SHOW, $aGUIChildren[GUICtrlRead($Tabs)])
        EndSwitch
    WEnd
EndFunc

Func SubGui($aGUIChildren,$index,$Disabled=False)
    $aGUIChildren[$index] = GUICreate("", 564, 409, 220, 70,$WS_POPUP,$WS_EX_MDICHILD,$RiskGUI)
$iStart = GUICtrlCreateDummy()
    $labArea[$index] = GUICtrlCreateLabel("Area", 13, 8, 70, 17)
$iEnd = GUICtrlCreateDummy()
    If $Disabled=True then
        For $i = $iStart To $iEnd
            GUICtrlSetState($i, $GUI_DISABLE)
        Next
    EndIf
    Return $aGUIChildren[$index]
EndFunc

Func LV_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView1,$hWndListView2,$hWndListView3,$hWndListView4, $tInfo
    If Not IsHWnd($idRisksFirst) Then $hWndListView1 = GUICtrlGetHandle($idRisksFirst)
    If Not IsHWnd($idRisksSecond) Then $hWndListView2 = GUICtrlGetHandle($idRisksSecond)
    If Not IsHWnd($idRisksThird) Then $hWndListView3 = GUICtrlGetHandle($idRisksThird)
    If Not IsHWnd($idRisksFinal) Then $hWndListView4 = GUICtrlGetHandle($idRisksFinal)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView1
            Switch $iCode
                Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    MsgBox(0,"","Left Click on First Line")
                Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button
                    MsgBox(0,"","Right Click on First Line")
            EndSwitch
        Case $hWndListView2
            Switch $iCode
                Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    MsgBox(0,"","Left Click on Second Line")
                    GUICtrlSetState($tabs,$GUI_ENABLE)
                Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button
                    MsgBox(0,"","Right Click on Second Line")
            EndSwitch
        Case $hWndListView3
            Switch $iCode
                Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    MsgBox(0,"","Left Click on Third Line")
                Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button
                    MsgBox(0,"","Right Click on Third Line")
            EndSwitch
        Case $hWndListView4
            Switch $iCode
                Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    MsgBox(0,"","Left Click on Final Line")
                Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button
                    MsgBox(0,"","Right Click on Final Line")
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

Edited by Jewtus

Share this post


Link to post
Share on other sites



Jewtus,

You cannot "disable" a tab - the best I have ever come up with is preventing it being selected:

https://www.autoitscript.com/forum/topic/162885-help-with-disablegray-out-one-tab/?do=findComment&comment=1185314

So you would need to set a flag when your ListViews 1-3 are clicked and only allow the relevant tab to be selected. When ListView 4 is selected you allow all tabs to be selected.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Well I want the tabs to stay active, just not the elements in the tab. I think I'm going to ditch the sub GUIs and just declare all the fields/values and then just activate/disable the elements on each tab when the listview is clicked.

 

Thanks for the info.

Share this post


Link to post
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

  • Similar Content

    • crazyjts
      By crazyjts
      Hi all,
      I have the following snippet of code that sort of works but isn’t doing exactly what I want.
      expand popup #include <GuiConstants.au3> Global $gGUIWidth = 250 Global $gGUIHeight = 150 Initial() Func Initial()    ; Create the initial GUI    $BaseGUI = GUICreate("", $gGUIWidth, $gGUIHeight, -1, -1, -1, $WS_EX_TOPMOST + $WS_EX_TOOLWINDOW)    GUISetState(@SW_SHOW, $BaseGUI)    ; Create a field for entering the current value    GUICtrlCreateLabel("Current Value:",  10, 10)    $CurrentValueFld = GUICtrlCreateInput("", 10, 40, 215, 20, $ES_NUMBER)    GUICtrlSetState($CurrentValueFld, $GUI_FOCUS)    ; Create Calculate button    Local $CalculateButton = GUICtrlCreateButton("Calculate", 10, 70, 75, 25)    GUICtrlSetState($CalculateButton, $GUI_DISABLE)    ; Watch the value field and determine if the value is greater than 0 and if so, enable Calculate button    $i = 0    Do       $CurrentValue = GUICtrlRead($CurrentValueFld)       If $CurrentValue > 0 Then          GUICtrlSetState($CalculateButton, $GUI_ENABLE + $GUI_FOCUS)          $i = 1       EndIf    until $i = 1    ;Loop until the user exits and check for ESC, "X", or Begin button    While 1       $InitialGUIMsg = GUIGetMsg()       If $InitialGUIMsg = $GUI_EVENT_CLOSE Then          Exit       EndIf    WEnd EndFunc  
      I want to be able to:
        Start with focus in the value field (it is doing this now)  Allow for more than one digit to be entered into the field (it is sort of doing this now but I have to bring focus back to the field) Enable the Calculate button and give focus to it once a value is entered into the value field (it is doing this now) but keep the cursor in the value field so the more digits can be entered (it is not doing this now) Be able to hit ESC or “X” to close the dialog at any time (this only works after I enter a digit in the value field Basically, I want to be able to allow the user to enter one or more digits and hit ENTER or SPACE (while the cursor is still in the value field) to push the Calculate button.  I assume I need to bring focus to the button but maybe I don't and can get away with assigning hotkeys for ENTER and SPACE to push the Calculate button while keeping focus in the value field.
      If you could, please add comments in your code as to what the changes are doing if they aren't obvious to a noobish programmer.  
      Thanks for any help you can offer on this.
    • TheOnlyOne
      By TheOnlyOne
      Hello, I am trying to hide all the controls in my GUI. Is it possible to do an easier way than to use GUICtrlSetState on every single Control I have?