Jump to content

GUI driven based on listview


Jewtus
 Share

Recommended Posts

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

  • Moderators

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

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

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.

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

×
×
  • Create New...