Clark Posted September 2, 2011 Share Posted September 2, 2011 (edited) This is the sort screen for a reporting app I am putting together for internal use. Each of the boxed areas is grouped, so that only one radio button can be active. BUT, when I select a radio button in a group, the same radio buttons in the other groups must be disabled. (As shown in the graphic) Now the only way I can see to do this is to write code for each and every button to do this, and also to find which other buttons might be disabled to re-activate them (say, if a user has previously selected a different radio button). That would be a lot of code and I am thinking there must be a simpler way. Is there a way for e.g. to have a radio button multi grouped? So in the graphic the Defect ID would be grouped within both "First by" and then also with the other radio buttons of the same name. Or is there a better way entirely to do this? I'm not hung up on radio buttons. Edited September 2, 2011 by Clark Link to comment Share on other sites More sharing options...
monoscout999 Posted September 2, 2011 Share Posted September 2, 2011 Maybe using arrays and a check variable and a function to do the job, it is not so hard, right now i can not write any snippet, but later i will post an example of what i am saying Clark 1 Link to comment Share on other sites More sharing options...
guinness Posted September 2, 2011 Share Posted September 2, 2011 (edited) I had this example in my function folder or you can search the forum too. expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <GUIConstantsEx.au3> #include <GUIMenu.au3> #include <WindowsConstants.au3> Global $aCheckbox[17][2] = [[16, 2]], $hContextMenu, $hGUI, $iButton, $iLeft = 8, $iTop = 8, $sChecked $hGUI = GUICreate("Multiple Checkbox Example", 365, 225) For $A = 1 To $aCheckbox[0][0] $aCheckbox[$A][0] = GUICtrlCreateCheckbox("Checkbox " & $A, $iLeft, $iTop, 95, 16) If Mod($A, 10) = 0 Then $iLeft *= 16 $iTop = 8 ContinueLoop EndIf $iTop += 20 Next $iButton = GUICtrlCreateButton("Sumbit", 232, 128, 75, 25) Global Enum $iContextItem_1 = 1000, $iContextItem_2 $hContextMenu = _GUICtrlMenu_CreatePopup() _GUICtrlMenu_InsertMenuItem($hContextMenu, 0, "Select All", $iContextItem_1) _GUICtrlMenu_InsertMenuItem($hContextMenu, 1, "Select None", $iContextItem_2) GUICtrlSetState(-1, $GUI_DISABLE) GUISetState(@SW_SHOW) AdlibRegister("Checkbox_Check", 200) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE AdlibUnRegister("Checkbox_Check") GUIRegisterMsg($WM_COMMAND, "") GUIRegisterMsg($WM_CONTEXTMENU, "") Exit Case $iButton $sChecked = "" For $A = 1 To $aCheckbox[0][0] If $aCheckbox[$A][1] Then $sChecked &= $A & ", " EndIf Next MsgBox(0, "Information", "Following Checkboxes Are Checked: " & @CRLF & @CRLF & StringTrimRight($sChecked, 2)) EndSwitch WEnd Func Checkbox_Check() Local $iAdd For $A = 1 To $aCheckbox[0][0] $aCheckbox[$A][1] = BitAND(GUICtrlRead($aCheckbox[$A][0]), $GUI_CHECKED) $iAdd += $aCheckbox[$A][1] Next If $iAdd Then If Not BitAND(GUICtrlGetState($iButton), $GUI_ENABLE) Then GUICtrlSetState($iButton, $GUI_ENABLE) EndIf Else If Not BitAND(GUICtrlGetState($iButton), $GUI_DISABLE) Then GUICtrlSetState($iButton, $GUI_DISABLE) EndIf EndIf EndFunc ;==>Checkbox_Check Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $ilParam Switch $iwParam Case $iContextItem_1 For $A = 1 To $aCheckbox[0][0] GUICtrlSetState($aCheckbox[$A][0], $GUI_CHECKED) Next Case $iContextItem_2 For $A = 1 To $aCheckbox[0][0] GUICtrlSetState($aCheckbox[$A][0], $GUI_UNCHECKED) Next EndSwitch Return "GUI_RUNDEFMSG" EndFunc ;==>WM_COMMAND Func WM_CONTEXTMENU($hWnd, $iMsg, $iwParam, $ilParam) #forceref $iMsg, $iwParam, $ilParam _GUICtrlMenu_TrackPopupMenu($hContextMenu, $hWnd) Return 1 EndFunc ;==>WM_CONTEXTMENU Edited September 2, 2011 by guinness UDF List:  _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Clark Posted September 2, 2011 Author Share Posted September 2, 2011 Thanks Guiness, I'm having trouble understanding how that applies to my particular question? I know how to check whether a particular button is pushed or not, and enabled or not, and in fact how to enable it, but to do that for every combination seems a lot of code. Link to comment Share on other sites More sharing options...
monoscout999 Posted September 2, 2011 Share Posted September 2, 2011 This is not very prolix but you can get an idea from here. expandcollapse popup#include <GUIConstantsEx.au3> Global $check = False $hGui = GUICreate("Check Radios", 300, 600) GUICtrlCreateGroup("group 1", 5, 5, 290, 190) Global $Checks1[6] Global $Width = 130 Global $Height = 40 Global $y = 20 Global $x = 10 Global $a = 0 For $i = 0 To UBound($Checks1) - 1 $Checks1[$i] = GUICtrlCreateRadio("Check 1 " & $i, $x + $Width * $a + $x * $a, $y, $Width, $Height) If $a = 1 Then $a = 0 $y = $Height + $y Else $a = 1 EndIf Next GUICtrlCreateGroup("", -99, -99, 1, 1) GUICtrlCreateGroup("group 2", 5, 205, 290, 190) Global $Checks2[6] $y = 220 For $i = 0 To UBound($Checks2) - 1 $Checks2[$i] = GUICtrlCreateRadio("Check 2 " & $i, $x + $Width * $a + $x * $a, $y, $Width, $Height) If $a = 1 Then $a = 0 $y = $Height + $y Else $a = 1 EndIf Next GUICtrlCreateGroup("", -99, -99, 1, 1) GUICtrlCreateGroup("group 3", 5, 405, 290, 190) Global $Checks3[6] $y = 420 For $i = 0 To UBound($Checks3) - 1 $Checks3[$i] = GUICtrlCreateRadio("Check 3 " & $i, $x + $Width * $a + $x * $a, $y, $Width, $Height) If $a = 1 Then $a = 0 $y = $Height + $y Else $a = 1 EndIf Next GUICtrlCreateGroup("", -99, -99, 1, 1) ; Just to release the memory $a = 0 $x = 0 $y = 0 $Width = 0 $Height = 0 ; ----------------------------- GUISetState() While True $iMsg = GUIGetMsg() Switch $iMsg Case -3 Exit Case $Checks1[0] To $Checks1[5] $check = Not $check EndSwitch If $check Then _CheckRadio() WEnd Func _CheckRadio() $check = Not $check For $i = 0 To UBound($Checks1) - 1 If BitAND(GUICtrlRead($Checks1[$i]), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($Checks2[$i], $GUI_DISABLE) GUICtrlSetState($Checks3[$i], $GUI_DISABLE) Else GUICtrlSetState($Checks2[$i], $GUI_ENABLE) GUICtrlSetState($Checks3[$i], $GUI_ENABLE) EndIf Next EndFunc ;==>_CheckRadio Link to comment Share on other sites More sharing options...
Clark Posted September 2, 2011 Author Share Posted September 2, 2011 Monoscout, you're a legend! Thankyou kindly sir. Link to comment Share on other sites More sharing options...
Spiff59 Posted September 3, 2011 Share Posted September 3, 2011 (edited) Arrays rock. This is the route I'd go: expandcollapse popup#include <Array.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $aGroup[4] = [0, "First by", "Then by", "Lastly by"] Global $aKey[7][2] = [[6, 0], ["Defect ID", 0], ["Defect Name", 0], ["Defect Status", 0], ["By Date", 0], ["By Reporter", 0], ["By Assignee", 0]] Global $Radio_Key[4][7] Global $Current_Group = 1 ;=================================================================================================================================== GUICreate("", 260, 345) For $x = 1 to 3 GUICtrlCreateGroup($aGroup[$x], 20, 100 * $x - 90, 220, 90) For $y = 1 to 3 $Radio_Key[$x][$y] = GUICtrlCreateRadio($aKey[$y][0], 30, 100 * $x + 20 * $y - 90, 85, 16) Next For $y = 1 to 3 $Radio_Key[$x][$y + 3] = GUICtrlCreateRadio($aKey[$y + 3][0], 135, 100 * $x + 20 * $y - 90, 85, 16) Next Next $Button_Clear = GUICtrlCreateButton("CLEAR", 40, 315, 80, 20) $Button_Sort = GUICtrlCreateButton("SORT", 140, 315, 80, 20) GUISetState() Update_Keys(-7) ;----------------------------------------------------------------------------------------------------------------------------------- While 1 $msg = GUIGetMsg() Switch $msg Case $Radio_Key[1][1] to $Radio_Key[3][6] $msg -= $Radio_Key[1][1] Update_Keys($msg - Int($msg / 7)) Case $Button_Clear Clear_Group() Update_Keys(-7) Case $Button_Sort _ArrayDisplay($aKey) Case -3 Exit EndSwitch WEnd ;================================================================================================================================== Func Update_Keys($ctrlid) Local $group = Int($ctrlid / 6) + 1, $radio = Mod($ctrlid, 6) + 1 If $radio Then $aKey[$radio][1] = $group; mark field as used in this group For $x = 1 to 6 ; lock this group as used If $x <> $radio Then GUICtrlSetState($Radio_Key[$group][$x], $GUI_DISABLE) Next If $Current_Group < 4 Then $Current_Group += 1 EndIf For $x = $Current_Group to 3 ; open "new" current group (if not used) then lock remaining groups For $y = 1 to 6 If Not $aKey[$y][1] And $x = $Current_Group Then GUICtrlSetState($Radio_Key[$x][$y], $GUI_ENABLE) Else GUICtrlSetState($Radio_Key[$x][$y], $GUI_DISABLE) EndIf Next Next EndFunc Func Clear_Group() If $Current_Group > 1 Then $Current_Group -= 1 For $x = 1 to 6 GUICtrlSetState($Radio_Key[$Current_Group][$x], $GUI_UNCHECKED) If $aKey[$x][1] = $Current_Group Then $aKey[$x][1] = 0 Next EndFunc Edit: Switched from |Code| tags to |Autoit| tags. Hopefully it'll better retain the source formatting... Edit2: Nope Edited September 3, 2011 by Spiff59 Link to comment Share on other sites More sharing options...
Clark Posted September 5, 2011 Author Share Posted September 5, 2011 Nice. That one is pretty clever also. 20 less lines, but I think the functionality given Monoscout's snippet is more like what I was looking for. Link to comment Share on other sites More sharing options...
Clark Posted September 5, 2011 Author Share Posted September 5, 2011 Actually, I spoke to soon. Unfortunately Monoscout's doesn't work properly, and I think it will be difficult for me to fix it. I will try Spiff's one instead. (Mono, if you are interested, the problem is that when you have selected a radio button in group 2 you can still select the same radio button in group 1. This is probably just my bad specification. I think Spiff's solution should avoid this problem entirely.) Thanks all. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now