Skip to content
⌘ NSIS Forum Archive

Selecting a checkbox automaticaly de-select another?

20 posts

TeenBurger#

Selecting a checkbox automaticaly de-select another?

lets say i have


section a-1

section a-2

section a-3

section b-1

section b-2

section b-3

how do i code it out for user to be able to select both a-1 and b-1 BUT only one of each of a-2 and b-2 and only one of a-3 and b-3 ?
TeenBurger#
the problem is that i cant un select a check thats in the macro


Function .onSelChange

!insertmacro StartRadioButtons $1
!insertmacro RadioButton ${g1o1}
!insertmacro RadioButton ${g1o2}
!insertmacro RadioButton ${g1o3}
!insertmacro EndRadioButtons

!insertmacro StartRadioButtons $2
!insertmacro RadioButton ${g2o1}
!insertmacro RadioButton ${g2o2}
!insertmacro RadioButton ${g2o3}
!insertmacro EndRadioButtons

FunctionEnd

if i insert


!insertmacro RadioButton 0

all the checkboxes will go blank but i only want one to go blank
TeenBurger#
Found a workaround


Function .onInit

StrCpy $1 ${g1o1} ; Group 1 - Option 1 is selected by default
StrCpy $2 ${g2o1} ; Group 2 - Option 1 is selected by default

FunctionEnd

Function .onSelChange

!insertmacro StartRadioButtons $1
!insertmacro RadioButton ${g1o1}
!insertmacro RadioButton $10
!insertmacro RadioButton ${g1o2}
!insertmacro RadioButton $11
!insertmacro RadioButton ${g1o3}
!insertmacro RadioButton $12
!insertmacro EndRadioButtons

!insertmacro StartRadioButtons $2
!insertmacro RadioButton ${g2o1}
!insertmacro RadioButton $13
!insertmacro RadioButton ${g2o2}
!insertmacro RadioButton $14
!insertmacro RadioButton ${g2o3}
!insertmacro RadioButton $15
!insertmacro EndRadioButtons

FunctionEnd


a little bit ugly but it works pretty well 🙂
Afrow UK#
This works
Section a-1 a-1
SectionEnd

Section a-2 a-2
SectionEnd

Section a-3 a-3
SectionEnd

Section b-1 b-1
SectionEnd

Section b-2 b-2
SectionEnd

Section b-3 b-3
SectionEnd

Var Sec1
Var Sec2

Function .onSelChange

!insertmacro StartRadioButtons $Sec1
!insertmacro RadioButton ${a-2}
!insertmacro RadioButton ${b-2}
!insertmacro EndRadioButtons

!insertmacro StartRadioButtons $Sec2
!insertmacro RadioButton ${a-3}
!insertmacro RadioButton ${b-3}
!insertmacro EndRadioButtons

FunctionEnd
-Stu
TeenBurger#
My Structure is

SectionGroup "Group1"

Section a-1 a-1
SectionEnd

Section a-2 a-2
SectionEnd

Section a-3 a-3
SectionEnd

SectionGroupEnd

SectionGroup "Group2"

Section b-1 b-1
SectionEnd

Section b-2 b-2
SectionEnd

Section b-3 b-3
SectionEnd

SectionGroupEnd

Var Sec1
Var Sec2

Function .onSelChange

!insertmacro StartRadioButtons $Sec1
!insertmacro RadioButton ${a-2}
!insertmacro RadioButton ${b-2}
!insertmacro EndRadioButtons

!insertmacro StartRadioButtons $Sec2
!insertmacro RadioButton ${a-3}
!insertmacro RadioButton ${b-3}
!insertmacro EndRadioButtons

FunctionEnd

i get weird result some checkboxes wont uncheck and sometimes i can check a-3 and b-3 at the same time
Afrow UK#
Fixed:
SectionGroup "Group1"

Section a-1 a-1
SectionEnd

Section a-2 a-2
SectionEnd

Section a-3 a-3
SectionEnd

SectionGroupEnd

SectionGroup "Group2"

Section b-1 b-1
SectionEnd

Section /o b-2 b-2
SectionEnd

Section /o b-3 b-3
SectionEnd

SectionGroupEnd

Var Sec1
Var Sec2

Function .onInit
StrCpy $Sec1 ${a-2}
StrCpy $Sec2 ${a-3}
FunctionEnd

Function .onSelChange

!insertmacro StartRadioButtons $Sec1
!insertmacro RadioButton ${a-2}
!insertmacro RadioButton ${b-2}
!insertmacro EndRadioButtons

!insertmacro StartRadioButtons $Sec2
!insertmacro RadioButton ${a-3}
!insertmacro RadioButton ${b-3}
!insertmacro EndRadioButtons

FunctionEnd
Is that what you want?

-Stu
TeenBurger#
SectionGroup "Group1"

Section a-1 a-1
SectionEnd

Section a-2 a-2
SectionEnd

Section a-3 a-3
SectionEnd

SectionGroupEnd

SectionGroup "Group2"

Section b-1 b-1
SectionEnd

Section /o b-2 b-2
SectionEnd

Section /o b-3 b-3
SectionEnd

SectionGroupEnd

Var Sec1
Var Sec2

Function .onInit
StrCpy $Sec1 ${a-2}
StrCpy $Sec2 ${a-3}
FunctionEnd

Function .onSelChange
--loop--
!insertmacro StartRadioButtons $Sec1
!insertmacro RadioButton ${a-2}
!insertmacro RadioButton ${null}
!insertmacro RadioButton ${b-2}
!insertmacro RadioButton ${null}
!insertmacro EndRadioButtons
--gotoloop--
!insertmacro StartRadioButtons $Sec2
!insertmacro RadioButton ${a-3}
!insertmacro RadioButton ${b-3}
!insertmacro EndRadioButtons

FunctionEnd

how do i do that ?
TeenBurger#
Originally posted by Afrow UK
Fixed:
SectionGroup "Group1"

Section a-1 a-1
SectionEnd

Section a-2 a-2
SectionEnd

Section a-3 a-3
SectionEnd

SectionGroupEnd

SectionGroup "Group2"

Section b-1 b-1
SectionEnd

Section /o b-2 b-2
SectionEnd

Section /o b-3 b-3
SectionEnd

SectionGroupEnd

Var Sec1
Var Sec2

Function .onInit
StrCpy $Sec1 ${a-2}
StrCpy $Sec2 ${a-3}
FunctionEnd

Function .onSelChange

!insertmacro StartRadioButtons $Sec1
!insertmacro RadioButton ${a-2}
!insertmacro RadioButton ${b-2}
i need a field here that will let me uncheck the box without breaking the macro
!insertmacro EndRadioButtons
!insertmacro StartRadioButtons $Sec2
!insertmacro RadioButton ${a-3}
!insertmacro RadioButton ${b-3}
!insertmacro EndRadioButtons

FunctionEnd
Is that what you want?

-Stu
Guest#
you how come this can't work

${If} ${SectionIsSelected} ${a-2}
SectionSetFlags ${b-2} "0"
${Else}
SectionSetFlags ${b-2} "1"
${EndIf}

${If} ${SectionIsSelected} ${b-2}
SectionSetFlags ${a-2} "0"
${Else}
SectionSetFlags ${a-2} "1"
${EndIf}

${If} ${SectionIsSelected} ${a-3}
SectionSetFlags ${b-3} "0"
${Else}
SectionSetFlags ${b-3} "1"
${EndIf}

${If} ${SectionIsSelected} ${b-3}
SectionSetFlags ${a-3} "0"
${Else}
SectionSetFlags ${a-3} "1"
${EndIf}
Afrow UK#
To do what you want would require you to modify the code in Sections.nsh itself.
I think it'd be easier to just have another radio button in the 1st radio-buttons block which had "No a-2, b-2" as a title (to the effect).

NHOCSUNG, are you asking us if your code works, or asking why we shouldn't use it because it does work? It doesn't work 😛

-Stu