Jump to content

Enaible/Disable Radio buttons depends on the value in List


 Share

Recommended Posts

Hello everybody,

I would like to ask you for help.

I have a simple application which has a list with items, several radio buttons and button starting the explorer.

This is what I need to have:

When I select some item in the list, I need Radio buttons changed. For example: when I press on item "3" I need several new radio buttons appear below of first ones. And If I select another item after that new radios will disappear.

This is the script:

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

Navigator()

Func Navigator()
    Local $hGUI1, $menu1, $n1, $radioPROD, $n3, $n4, $radioUAT, $radioMARKET, $radioINTERFACE,$radioPROD_RUS1, $radioPROD_RUS2, $radioPROD_RUS3, $radioPROD_RUS6,$hGUI2, $msg, $msg2, $srv, $menustate, $menutext, $widthCell, $server
    
    $hGUI1 = GUICreate("Navigator")

    $n1 = GUICtrlCreateList("", 10, 10, -1, 300)
    GUICtrlSetData(-1, "1|2|3", "item2")
    
    $widthCell = 200
    GUICtrlCreateLabel("Radios", 220, 10, $widthCell)
    $radioPROD = GUICtrlCreateRadio("PROD", 220, 25, 50, 20)
    $radioUAT = GUICtrlCreateRadio("UAT", 300, 25, 100, 20)
    

    $n3 = GUICtrlCreateButton("Open", 10, 310, 50)
    GUICtrlSetState(-1, $GUI_FOCUS)

    GUISetState()
    
    Do
        $msg = GUIGetMsg()

        If $msg = $n3 and GUICtrlRead($radioPROD) = 1 and GUICtrlRead($n1) = '1' Then
            Run("explorer.exe \\swigva01-srv125\siebsrvr1\DOCKING")
        EndIf
        
        If $msg = $n3 and GUICtrlRead($radioPROD) = 1 and GUICtrlRead($n1) = '2' Then
            Run("explorer.exe \\swigva01-srv120\siebsrvr1\DOCKING")
        EndIf
                
        If $msg = $n3 and GUICtrlRead($radioPROD) = 1 and GUICtrlRead($n1) = '3' Then
            Run("explorer.exe \\swigva01-srv120\siebsrvr1\DOCKING")
        EndIf
    
    Until $msg = $GUI_EVENT_CLOSE
EndFunc

Thank you in advanse.

Link to comment
Share on other sites

  • Moderators

zotchy,

Welocme the the AutoIt forum. :)

I suggest you create all the radios you need when you create the GUI and thne use $GUI_HIDE/SHOW as required. ;)

This modified version of your script shows you the idea:

#include <GUIConstantsEx.au3>

Navigator()

Func Navigator()
    
    $hGUI1 = GUICreate("Navigator")

    $n1 = GUICtrlCreateList("", 10, 10, -1, 300)
    GUICtrlSetData(-1, "1|2|3", "item2")

    $widthCell = 200
    GUICtrlCreateLabel("Radios", 220, 10, $widthCell)
    $radioPROD = GUICtrlCreateRadio("PROD", 220, 25, 50, 20)
    $radioUAT = GUICtrlCreateRadio("UAT", 300, 25, 100, 20)

    $radio_Extra_1 = GUICtrlCreateRadio("Extra 1", 220, 55, 80, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    $radio_Extra_2 = GUICtrlCreateRadio("Extra 1", 300, 55, 80, 20)
    GUICtrlSetState(-1, $GUI_HIDE)

    $n3 = GUICtrlCreateButton("Open", 10, 310, 50)
    GUICtrlSetState(-1, $GUI_FOCUS)

    GUISetState()

    Do
        $msg = GUIGetMsg()

        If $msg = $n3 and GUICtrlRead($radioPROD) = 1 and GUICtrlRead($n1) = '1' Then
            Run("explorer.exe \\swigva01-srv125\siebsrvr1\DOCKING")
        EndIf

        If $msg = $n3 and GUICtrlRead($radioPROD) = 1 and GUICtrlRead($n1) = '2' Then
            Run("explorer.exe \\swigva01-srv120\siebsrvr1\DOCKING")
        EndIf

        If $msg = $n3 and GUICtrlRead($radioPROD) = 1 and GUICtrlRead($n1) = '3' Then
            Run("explorer.exe \\swigva01-srv120\siebsrvr1\DOCKING")
        EndIf

        If $msg = $n1 Then
            If GUICtrlRead($n1) = "3" Then
                GUICtrlSetState($radio_Extra_1, $GUI_SHOW)
                GUICtrlSetState($radio_Extra_2, $GUI_SHOW)
            Else
                GUICtrlSetState($radio_Extra_1, $GUI_HIDE)
                GUICtrlSetState($radio_Extra_2, $GUI_HIDE)
            EndIf
        EndIf

    Until $msg = $GUI_EVENT_CLOSE
EndFunc

All clear? ;)

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

Dear Melba23,

Thank you very much for your reply. This is what I need.

Only one thing I faced. When I add 2 extra hidden buttons, only two are visible. Very strange because I checked the location parameters several times. Seems that it touched only hidden buttons, because I am able to add several which is visible from the start of application.

Thank you in advance and sorry for such elementary questions. I am newbie.

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