How can I check a radio button after multiple are programmatically created? Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
IMTheNachoMan
Posts: 59
Joined: 01 Mar 2022, 17:07
Contact:

How can I check a radio button after multiple are programmatically created?

21 Sep 2023, 21:36

I am programatically creating multiple radio buttons like so:

Code: Select all

radioName := " VmyDetails"
for k, v in obj
{
   myGUI.add("Radio", radioName, k)
   radioName := ""
}
I know I can get the selected radio button like so:

Code: Select all

selectedRadioIndex := myGUI.Submit(False).myDetails
But, before I show the GUI, I want to find a radio button by it's index and check it. How can I do that?

I can't check the radio buttons while they are being created. The GUI will be shown/hidden numerous times and each time a different radio button should be selected.
teadrinker
Posts: 4365
Joined: 29 Mar 2015, 09:41
Contact:

Re: How can I check a radio button after multiple are programmatically created?  Topic is solved

22 Sep 2023, 01:53

I'm not sure I got what you were trying to accomplish, but probably something like this:

Code: Select all

wnd := Gui()
for k, v in ['one', 'two', 'three', 'four', 'fife'] {
    wnd.AddRadio(k = 1 ? 'VmyDetails' : '', v)
}
; check 3rd radio
firstRadioClassNN := ControlGetClassNN(wnd['myDetails'])
firstRadioNumber := SubStr(firstRadioClassNN, 7)
wnd['Button' . (firstRadioNumber + 2)].Value := 1
wnd.Show()
just me
Posts: 9526
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: How can I check a radio button after multiple are programmatically created?

22 Sep 2023, 05:12

Another option:

Code: Select all

#Requires AutoHotkey 2.0
#Warn
RadioButtons := ["One", "Two", "Three", "Four", "Five"]
Wnd := Gui()
Wnd.OnEvent("Close", (*) => ExitApp())
RadioGroup := []
For K, V In RadioButtons {
   RadioGroup.Push(Wnd.AddRadio("xm w300", V))
}
; check 3rd radio
RadioGroup[3].Value := 1
Wnd.AddButton("xm w300", "Get checked").OnEvent("Click", GetCheckedRadio)
Wnd.Show()

GetCheckedRadio(*) {
   Local CheckedRadio := 0
   For I, RadioCtrl In RadioGroup
      CheckedRadio := RadioCtrl.Value ? I : 0
   Until CheckedRadio
   MsgBox(CheckedRadio)
}
songdg
Posts: 607
Joined: 04 Oct 2017, 20:04

Re: How can I check a radio button after multiple are programmatically created?

23 Sep 2023, 22:07

@just me
How to make the RadioGroup horizontal?

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: aleape, Descolada and 38 guests