KickStarter15 Posted May 11, 2017 Share Posted May 11, 2017 Hi Experts, I have this code that I need to shorten it. expandcollapse popupIf GUICtrlRead($Error1) = $GUI_CHECKED Then GUICtrlSetState($Edit1, $GUI_Enable) Else GUICtrlSetState($Edit1, $GUI_Disable) EndIf Case $Error2 If GUICtrlRead($Error2) = $GUI_CHECKED Then GUICtrlSetState($Edit2, $GUI_Enable) Else GUICtrlSetState($Edit2, $GUI_Disable) EndIf Case $Error3 If GUICtrlRead($Error3) = $GUI_CHECKED Then GUICtrlSetState($Edit3, $GUI_Enable) Else GUICtrlSetState($Edit3, $GUI_Disable) EndIf Case $Error4 If GUICtrlRead($Error4) = $GUI_CHECKED Then GUICtrlSetState($Edit4, $GUI_Enable) Else GUICtrlSetState($Edit4, $GUI_Disable) EndIf Case $Error5 If GUICtrlRead($Error5) = $GUI_CHECKED Then GUICtrlSetState($Edit5, $GUI_Enable) Else GUICtrlSetState($Edit5, $GUI_Disable) EndIf Case $Error6 If GUICtrlRead($Error6) = $GUI_CHECKED Then GUICtrlSetState($Edit6, $GUI_Enable) Else GUICtrlSetState($Edit6, $GUI_Disable) EndIf Case $Error7 If GUICtrlRead($Error7) = $GUI_CHECKED Then GUICtrlSetState($Edit7, $GUI_Enable) Else GUICtrlSetState($Edit7, $GUI_Disable) EndIf Case $Error8 If GUICtrlRead($Error8) = $GUI_CHECKED Then GUICtrlSetState($Edit8, $GUI_Enable) Else GUICtrlSetState($Edit8, $GUI_Disable) EndIf Case $Error9 If GUICtrlRead($Error9) = $GUI_CHECKED Then GUICtrlSetState($Edit9, $GUI_Enable) Else GUICtrlSetState($Edit9, $GUI_Disable) EndIf Case $Error10 If GUICtrlRead($Error10) = $GUI_CHECKED Then GUICtrlSetState($Edit10, $GUI_Enable) Else GUICtrlSetState($Edit10, $GUI_Disable) EndIf $Error is a checkbox that when ticked $EditBox will disable and enable as shown above. I need to shorten this code for easy tracking and if I need to add more checkbox. This is just simple but could not compile one. Funny... Thanks in advance Experts, KS15 Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
Subz Posted May 11, 2017 Share Posted May 11, 2017 Here is a basic example: a. Create ComboBox.txt with the following text: Text is CSV with the following parameters Varx = CheckBox Variable id Label x = CheckBox Label x Position y Position width height Editx = InputBox Variable associated with CheckBox Var1,Label 1,5,5,100,20,Edit1 Var2,Label 2,5,25,100,20,Edit2 Var3,Label 3,5,45,100,20,Edit3 Var4,Label 4,5,65,100,20,Edit4 Var5,Label 5,5,85,100,20,Edit5 You can then use something like the following for automatically toggling $GUI_Disable/$GU_Enable expandcollapse popup#Include <Array.au3> #include <File.au3> #include <GUIConstantsEx.au3> Global $aCheckBox[0], $aInputBox[0] _Example() Func _Example() Local $aFileRead, $aStringSplit Local $idCancel GUICreate('', 210, 140) _FileReadToArray('CheckBox.txt', $aFileRead) ReDim $aCheckBox[$aFileRead[0]] ReDim $aInputBox[$aFileRead[0]] For $i = 1 To $aFileRead[0] $aStringSplit = StringSplit($aFileRead[$i], ',', 2) If UBound($aStringSplit) -1 = 6 Then Assign($aStringSplit[0], GUICtrlCreateCheckbox($aStringSplit[1], Number($aStringSplit[2]), Number($aStringSplit[3]), Number($aStringSplit[4]), Number($aStringSplit[5])), 2) Assign($aStringSplit[6], GUICtrlCreateInput('', Number($aStringSplit[2]) + Number($aStringSplit[4]), Number($aStringSplit[3]), Number($aStringSplit[4]), Number($aStringSplit[5])), 2) $aCheckBox[$i - 1] = $aStringSplit[0] $aInputBox[$i - 1] = $aStringSplit[6] EndIf Next $idCancel = GUICtrlCreateButton('Cancel', 5, 110, 95, 25) GUISetState() AdlibRegister("CheckBox") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idCancel ExitLoop EndSwitch WEnd EndFunc Func CheckBox() For $i = 0 To UBound($aCheckBox) - 1 If GUICtrlRead(Eval($aCheckBox[$i])) = $GUI_CHECKED Then GUICtrlSetState(Eval($aInputBox[$i]), 64) Else ConsoleWrite("Checkbox" & $aCheckBox[$i] & @CRLF & "InputBox" & $aInputBox[$i] & @CRLF) GUICtrlSetState(Eval($aInputBox[$i]), 128) EndIf Next EndFunc KickStarter15 1 Link to comment Share on other sites More sharing options...
Malkey Posted May 11, 2017 Share Posted May 11, 2017 (edited) Another example. #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> _Checkbox_EditCtrl() Func _Checkbox_EditCtrl() Local $hGUI = GUICreate("Example", 400, 410) Local $Number = 20, $iRows = 10, $iSpacing = 5 Local $Error[$Number] ; Array holding Checkbox controls ids Local $Edit[$Number] ; Array holding Edit controls ids ; Create checkbox controls. For $i = 0 To $Number - 1 ; id's are sequentially numbered starting at $Error[0] $Error[$i] = GUICtrlCreateCheckbox("ChkBx" & $i + 1, $iSpacing + (Int($i / $iRows) * 190), ((40 * Mod($i, $iRows)) + $iSpacing), 80, 20) ; Next ; Create Edit controls. For $i = 0 To $Number - 1 ; id's are sequentially numbered starting at $Edit[0] $Edit[$i] = GUICtrlCreateEdit("Edit" & $i + 1, $iSpacing + 80 + (Int($i / $iRows) * 190), ((40 * Mod($i, $iRows)) + $iSpacing), 95, 40, BitOR($ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL), BitOR($WS_EX_CLIENTEDGE, $WS_EX_ACCEPTFILES)) ; GUICtrlSetState($Edit[$i], $GUI_Disable) Next GUISetState(@SW_SHOW, $hGUI) While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ;, $idClose ExitLoop Case $Error[0] To $Error[($Number - 1)] $iIndex = $msg - $Error[0] ; Array Index GUICtrlSetState($Edit[$iIndex], (BitAND(GUICtrlRead($Error[$iIndex]), $GUI_CHECKED) = $GUI_CHECKED ? BitOR($GUI_Enable, $GUI_FOCUS) : $GUI_Disable)) EndSwitch WEnd GUIDelete($hGUI) EndFunc ;==>_Checkbox_EditCtrl Edited May 12, 2017 by Malkey Commented out un-needed $idClose variable. Making CheckBox 6 exit script. Subz and KickStarter15 2 Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted May 11, 2017 Share Posted May 11, 2017 @Subz He was looking for something more comptact @KickStarter15 Look at the code below, and ask if you don't understand something. expandcollapse popup#include <MsgBoxConstants.au3> #include <Array.au3> ; These are your checkboxes, declared as Local or Global ( for use them in functions ) Local $checkbox_First, $checkbox_Second, $checkbox_Third ; These are your edits Local $edit_First, $edit_Second, $edit_Third Local $aCheckboxes[] = [$checkbox_First, $checkbox_Second, $checkbox_Third] ; You can work with more checkboxes as you want... Local $aEdits[] = [$edit_First, $edit_Second, $edit_Third] ; Same as above ; The user checks checkboxes in the GUI ; ; 0 = NOT CHECKED ; 1 = CHECKED $aCheckboxes[0] = 1 $aCheckboxes[1] = 0 $aCheckboxes[2] = 1 For $i = 0 To UBound($aCheckboxes) - 1 If($aCheckboxes[$i] == 1) Then ; $GUI_CHECKED ConsoleWrite("The checkbox " & $aCheckboxes[$i] & " is checked." & @CRLF) $aEdits[$i] = 1 Else ConsoleWrite("The checkbox " & $aCheckboxes[$i] & " is not checked." & @CRLF) $aEdits[$i] = 0 EndIf Next ; Show edits status _ArrayDisplay($aEdits, "Edits Status") Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Subz Posted May 11, 2017 Share Posted May 11, 2017 @FrancescoDiMuro Technically all the answers are the same, i.e. hold the control handles in an Array then query them in a loop, Malkey and i have just include the creation of the Gui, I used AdlibRegister function to detect the changes and Malkey used black magic Link to comment Share on other sites More sharing options...
KickStarter15 Posted May 12, 2017 Author Share Posted May 12, 2017 Hi Experts, It's more complex than I though, I never though that simple code can cause beast combinations. Thank you so much guys for sharing, I'll check all of these given sample ideas and see what comes up. I'll let you know the result. KS15 Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
Floops Posted May 12, 2017 Share Posted May 12, 2017 (edited) If you don't want to create an array of controls you can also try this, but it isn't as short as the other solutions in here. Execute(GUICtrlRead($Error1) = $GUI_CHECKED ? GUICtrlSetState($Edit1, $GUI_Enable) : GUICtrlSetState($Edit1, $GUI_Disable)) Execute(GUICtrlRead($Error2) = $GUI_CHECKED ? GUICtrlSetState($Edit2, $GUI_Enable) : GUICtrlSetState($Edit2, $GUI_Disable)) Execute(GUICtrlRead($Error3) = $GUI_CHECKED ? GUICtrlSetState($Edit3, $GUI_Enable) : GUICtrlSetState($Edit3, $GUI_Disable)) Execute(GUICtrlRead($Error4) = $GUI_CHECKED ? GUICtrlSetState($Edit4, $GUI_Enable) : GUICtrlSetState($Edit4, $GUI_Disable)) Execute(GUICtrlRead($Error5) = $GUI_CHECKED ? GUICtrlSetState($Edit5, $GUI_Enable) : GUICtrlSetState($Edit5, $GUI_Disable)) Execute(GUICtrlRead($Error6) = $GUI_CHECKED ? GUICtrlSetState($Edit6, $GUI_Enable) : GUICtrlSetState($Edit6, $GUI_Disable)) Execute(GUICtrlRead($Error7) = $GUI_CHECKED ? GUICtrlSetState($Edit7, $GUI_Enable) : GUICtrlSetState($Edit7, $GUI_Disable)) Execute(GUICtrlRead($Error8) = $GUI_CHECKED ? GUICtrlSetState($Edit8, $GUI_Enable) : GUICtrlSetState($Edit8, $GUI_Disable)) Execute(GUICtrlRead($Error9) = $GUI_CHECKED ? GUICtrlSetState($Edit9, $GUI_Enable) : GUICtrlSetState($Edit9, $GUI_Disable)) Execute(GUICtrlRead($Error10) = $GUI_CHECKED ? GUICtrlSetState($Edit10, $GUI_Enable) : GUICtrlSetState($Edit10, $GUI_Disable)) Edited May 12, 2017 by Floops Link to comment Share on other sites More sharing options...
KickStarter15 Posted May 12, 2017 Author Share Posted May 12, 2017 Here it is Experts, @Subz, Amazing combinations you've got there and it's more efficient to use if I'll be using CheckBox.txt as source database, With it I can easily add how many checkboxes and edited boxes i need. One question, in the below code, do I have to declare "Number($aStringSplit[6])" or just leave it as is. It's confusing me if that affects, however when tested, all are well without adding "Number($aStringSplit[6])" after the 5th. Assign($aStringSplit[0], GUICtrlCreateCheckbox($aStringSplit[1], Number($aStringSplit[2]), Number($aStringSplit[3]), Number($aStringSplit[4]), Number($aStringSplit[5])), 2) @Malkey, Simplicity is the best policy indeed as what the below code emphasis. Local $Number = 20, $iRows = 10, $iSpacing = 5 However, when ticking ChxBx6, GUI closed. Considering that it was already declared as value in range from the above code. Why is that so? For $i = 0 To $Number - 1 ; id's are sequentially numbered starting at $Error[0] $Error[$i] = GUICtrlCreateCheckbox("ChkBx" & $i + 1, $iSpacing + (Int($i / $iRows) * 190), ((40 * Mod($i, $iRows)) + $iSpacing), 80, 20) ; Next ; Create Edit controls. For $i = 0 To $Number - 1 ; id's are sequentially numbered starting at $Edit[0] $Edit[$i] = GUICtrlCreateEdit("Edit" & $i + 1, $iSpacing + 80 + (Int($i / $iRows) * 190), ((40 * Mod($i, $iRows)) + $iSpacing), 95, 40, BitOR($ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL), BitOR($WS_EX_CLIENTEDGE, $WS_EX_ACCEPTFILES)) ; GUICtrlSetState($Edit[$i], $GUI_Disable) Next @FrancescoDiMuro, The less code the better isn't it.... with those 18 lines of code my problem solved actually. But, still I need to declare those additional checkboxes and editboxes in the below line which can cause +1 in declared line right?. Possible count of checkboxes and editboxes to be added in my code is around 1 to 50 (but of course all of these are scrolled down and up to hide them GUI). Local $checkbox_First, $checkbox_Second, $checkbox_Third, $checkbox_Forth Local $edit_First, $edit_Second, $edit_Third, $edit_Forth Local $aCheckboxes[] = [$checkbox_First, $checkbox_Second, $checkbox_Third, $checkbox_Forth] Local $aEdits[] = [$edit_First, $edit_Second, $edit_Third, $edit_Forth] @Floops, Thanks for sharing but it's just the same as what I posted here in this forum. Appreciated. Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
Malkey Posted May 12, 2017 Share Posted May 12, 2017 (edited) @KickStarter15 Just fixed it. I had copied an example from AutoIt help file which had an exit button that I deleted. But I left the variable, $idClose in the Switch exit Case. It now works as it is supposed to. Also, you can vary the number of check boxes by just varying the variable, $Number. Malkey Edit: I found out why pressing CheckBox6 use to exit the script in my example above. In the include file "MsgBoxConstants.au3" there is "Global Const $IDCLOSE = 8". The id for CheckBox6 in $Error[5] is also 8. That is why when $idClose is in the Switch exit Case, and, CheckBox6 is pressed, then $msg = 8. And $msg is first matched with $idClose and exits script. Edited May 12, 2017 by Malkey Link to comment Share on other sites More sharing options...
Floops Posted May 12, 2017 Share Posted May 12, 2017 @KickStarter15 Yes, my example is the same as yours functionality-wise. But it is more compact and easily expandable by just duplicating the line (CTRL + D in Scite). It's an alternative to using an array while still trying to keep it compact. Just wanted to throw out a different approach to the problem. Link to comment Share on other sites More sharing options...
Subz Posted May 12, 2017 Share Posted May 12, 2017 Sorry for the confusion the Array is 0 based so in actual fact $aStringSplit[5] is the 6th parameter. Hope that makes sense. Link to comment Share on other sites More sharing options...
KickStarter15 Posted May 12, 2017 Author Share Posted May 12, 2017 @Subz, Now I get it, so basically still need to declare in that line the succeeding "$aStringSplit[]" of how many checkboxes I wanted. 6 minutes ago, Subz said: in actual fact $aStringSplit[5] is the 6th parameter @Floops, Yes, agreed. That could help as well with some of my codes on-going right now but most probably I'll use an array as well for this concern. Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
KickStarter15 Posted May 12, 2017 Author Share Posted May 12, 2017 @Malkey, Thanks, just tested. It is now working. Now all I need to do is combine it to my code and see what comes up. Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
KickStarter15 Posted May 12, 2017 Author Share Posted May 12, 2017 (edited) @Subz and @Malkey, Guys, I made the script combining your both suggestions and it work as I needed. Thank you so much for your time, greatly appreciated Guys... @Malkey I made 300 checkboxes and 100 EditBoxes and it only consumes 18 lines. Local $Number = 100, $iRows = 100, $iSpacing = 205 Local $Error[$Number] Local $nError[$Number] Local $NA[$Number] Local $Edit[$Number] For $i = 0 To $Number - 1 $Error[$i] = GUICtrlCreateCheckbox("", $iSpacing + -40 + (Int($i / $iRows)), ((27.7 * Mod($i, $iRows)) + $iSpacing), 15, 20) Next For $j = 0 To $Number - 1 $nError[$j] = GUICtrlCreateCheckbox("", $iSpacing + 70 + (Int($j / $iRows)), ((27.7 * Mod($j, $iRows)) + $iSpacing), 15, 20) Next For $x = 0 To $Number - 1 $NA[$x] = GUICtrlCreateCheckbox("", $iSpacing + 172 + (Int($x / $iRows)), ((27.7 * Mod($x, $iRows)) + $iSpacing), 15, 20) Next For $i = 0 To $Number - 1 $Edit[$i] = GUICtrlCreateEdit("", $iSpacing + 400 + (Int($i / $iRows)), ((27.7 * Mod($i, $iRows)) + $iSpacing), 240, 24, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN)) ; GUICtrlSetState($Edit[$i], $GUI_Disable) Next Edited May 12, 2017 by KickStarter15 Edited with additional Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
KickStarter15 Posted May 13, 2017 Author Share Posted May 13, 2017 @Malkey, Good day, I have few little questions and need help with the below. Q1: Why does "For...To...Next" below won't allow something like this: Local $Number = 10, $iRows = 10, $iSpacing = 205 Local $Error[$Number] Local $nError[$Number] Local $NA[$Number] Local $Edit[$Number] For $i = 0 To $Number - 1 $Error[$i] = GUICtrlCreateCheckbox("", $iSpacing + -40 + (Int($i / $iRows)), ((27.7 * Mod($i, $iRows)) + $iSpacing), 15, 20) $nError[$i] = GUICtrlCreateCheckbox("", $iSpacing + 70 + (Int($i / $iRows)), ((27.7 * Mod($i, $iRows)) + $iSpacing), 15, 20) $NA[$i] = GUICtrlCreateCheckbox("", $iSpacing + 172 + (Int($i / $iRows)), ((27.7 * Mod($i, $iRows)) + $iSpacing), 15, 20) $Edit[$i] = GUICtrlCreateEdit("", $iSpacing + 250 + (Int($i / $iRows)), ((27.7 * Mod($i, $iRows)) + $iSpacing), 240, 24, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN)) GUICtrlSetState($Edit[$i], $GUI_Disable) Next Q2: How can I add above code in my $ListView, I did something like the below but I think I'm not doing it right. For $i = 1 To 10 ListView = GUICtrlCreateListView("ITEMS|ELEMENTS|ERROR|NO ERROR|NA|REMARKS", 100, 50, 480, 250, Default) GUICtrlCreateListViewItem($Error & $i&"|"&$nError & $i&"|"&$NA & $i&"|"&$Edit & $i, $ListView) Next Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
Malkey Posted May 13, 2017 Share Posted May 13, 2017 Q1 answer; The GUICtrlCreateCheckbox()'s and the GUICtrlCreateEdit() needs a Graphic User Interface (GUI or a window) to have those controls (Ctrl) to be created on. So you need to create a GUI (GUICreate()) for the Checkbox controls and the Edit control. Q2 answer: With this line, ListView = GUICtrlCreateListView("ITEMS|ELEMENTS|ERROR|NO ERROR|NA|REMARKS", 100, 50, 480, 250, Default) inside the For-Next loop, a ListView control will be created 10 times. - ListView should be a variable, $ListView. - Arrays are zero based. So the For-Next should be from zero to 10 - 1. $Error[0], $nError[0], $NA[0], and $Edit[0] are the first elements in each array. $i has to start at zero, 0. The last index has to be total number of elements in the array minus one. expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> _Checkbox_EditCtrl() Func _Checkbox_EditCtrl() Local $hGUI = GUICreate("Example", 1010, 1000) Local $Number = 10, $iRows = 10, $iSpacing = 305 Local $Error[$Number] Local $nError[$Number] Local $NA[$Number] Local $Edit[$Number] For $i = 0 To $Number - 1 $Error[$i] = GUICtrlCreateCheckbox("", $iSpacing + -40 + (Int($i / $iRows)), ((27.7 * Mod($i, $iRows)) + $iSpacing), 15, 20) $nError[$i] = GUICtrlCreateCheckbox("", $iSpacing + 70 + (Int($i / $iRows)), ((27.7 * Mod($i, $iRows)) + $iSpacing), 15, 20) $NA[$i] = GUICtrlCreateCheckbox("", $iSpacing + 172 + (Int($i / $iRows)), ((27.7 * Mod($i, $iRows)) + $iSpacing), 15, 20) $Edit[$i] = GUICtrlCreateEdit("Edit " & ($i + 1), $iSpacing + 250 + (Int($i / $iRows)), ((27.7 * Mod($i, $iRows)) + $iSpacing), 240, 24, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN)) GUICtrlSetState($Edit[$i], $GUI_Disable) Next Local $Listview = GUICtrlCreateListView("ITEMS|ELEMENTS|ERROR|NO ERROR|NA|REMARKS", $iSpacing - 40, 40, 480, 250, Default) For $i = 0 To 9 GUICtrlCreateListViewItem($i + 1 & "|" & $Error[$i] & "|" & $nError[$i] & "|" & $NA[$i] & "|" & $Edit[$i] & "|" & GUICtrlRead($Edit[$i]), $Listview) Next GUISetState(@SW_SHOW, $hGUI) While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ;ConsoleWrite( $idClose & " " & $msg & " " & $Error[5] & @CRLF) ExitLoop EndSwitch WEnd GUIDelete($hGUI) EndFunc ;==>_Checkbox_EditCtrl Link to comment Share on other sites More sharing options...
Malkey Posted May 13, 2017 Share Posted May 13, 2017 (edited) Case $Error[0] To $Error[($Number - 1)] $iIndex = $msg - $Error[0] ; Array Index For the above to work, the ID's contained in the array, $Error, must be created sequentially for the ID's in the array to contain sequential numbers. I used each control created in its own loop. Edit: It is simpler to create each control created in its own loop. But it is possible to create all the controls in one For - Next loop. This example is for three columns of CheckBox controls and one column of Edit controls. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <ListViewConstants.au3> ; https://www.autoitscript.com/forum/topic/188445-shorten-the-code/?do=findComment&comment=1353698 _Checkbox_EditCtrl() Func _Checkbox_EditCtrl() Opt("GUICoordMode", 2) ;1=absolute, 0=relative, 2=cell Global $hGUI = GUICreate("Example", 1270, 900, -1, -1, BitOR($WS_SIZEBOX, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX)) Global $Number = 20 * 4, $iCols = 4, $iHSpacing = 60, $iVSpacing = 10, $iBorder = 20, $Listview Global $aID[$Number] $idButt0 = GUICtrlCreateButton("All ChkBx A", 1, 1) GUICtrlSetPos($idButt0, 1160, 750, 100, 25) ; Used with Opt("GUICoordMode", 2) GUICtrlSetResizing($idButt0, $GUI_DOCKBOTTOM + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH) $idButt1 = GUICtrlCreateButton("All ChkBx B", -1, 5) ; Auto increase previous "top" by 5. "-1" indicates no increment. GUICtrlSetResizing($idButt1, $GUI_DOCKBOTTOM + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH) $idButt2 = GUICtrlCreateButton("All ChkBx C", -1, 5) ; Auto increase previous "top" by 5. "-1" indicates no increment. GUICtrlSetResizing($idButt2, $GUI_DOCKBOTTOM + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH) $idButt3 = GUICtrlCreateButton("Refresh List Virw", -1, 5) ; Auto increase previous "top" by 5. "-1" indicates no increment. GUICtrlSetResizing($idButt3, $GUI_DOCKBOTTOM + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH) For $i = 0 To $Number - 1 Step 4 $aID[$i] = GUICtrlCreateCheckbox("CheckBox " & (Int($i / 4) + 1) & " A", 1, 1) GUICtrlSetPos($aID[$i], $iBorder + $iHSpacing * (Mod($i, $iCols)), ((44 * Int($i / $iCols)) + $iVSpacing), 90, 20) ; Used with Opt("GUICoordMode", 2) $aID[$i + 1] = GUICtrlCreateCheckbox("CheckBox " & (Int($i / 4) + 1) & " B", $iHSpacing, -1) ; Auto increase previous "left" by $iHSpacing. "-1" indicates no increment. $aID[$i + 2] = GUICtrlCreateCheckbox("CheckBox " & (Int($i / 4) + 1) & " C", $iHSpacing, -1) ; Auto increase previous "left" by $iHSpacing. "-1" indicates no increment. $aID[$i + 3] = GUICtrlCreateEdit("Edit " & (Int($i / 4) + 1), $iHSpacing, -1, 240, 44, _ BitOR($ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL), BitOR($WS_EX_CLIENTEDGE, $WS_EX_ACCEPTFILES)) ; Auto increase previous "left" by $iHSpacing, and change "width" and "height" to 240 and 44. "-1" indicates no increment. Next ListViewData() GUISetState(@SW_SHOW, $hGUI) While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop Case $aID[0] To $aID[(UBound($aID) - 1)] For $j = 0 To $aID[UBound($aID) - 1] - 1 $iIndex = ($msg - $aID[0] - Mod($j, $iCols)) / $iCols ; Array Index If $iIndex - Int($iIndex) = 0 Then ConsoleWrite("Col:" & Mod($j, $iCols) & " Row:" & $iIndex & " " & GUICtrlRead($aID[$iIndex * $iCols + $iCols - 1]) & @CRLF) ExitLoop EndIf Next Case $idButt3 GUICtrlDelete($Listview) ListViewData() Case $idButt0 _AllCheck_Uncheck(0) ; Column 0 of checkboxes A Case $idButt1 _AllCheck_Uncheck(1) ; Column 1 of checkboxes B Case $idButt2 _AllCheck_Uncheck(2) ; Column 2 of checkboxes C EndSwitch WEnd GUIDelete($hGUI) EndFunc ;==>_Checkbox_EditCtrl Func ListViewData() $Listview = GUICtrlCreateListView("ITEMS|ChkBx A|ChkBx B|ChkBx C|Edit's id|Content of Edit", 1, 1, 1, 1, -1, $LVS_EX_CHECKBOXES) GUICtrlSetPos($Listview, 720, $iVSpacing, 530, 500) ; For $i = 0 To UBound($aID) - 1 Step 4 GUICtrlCreateListViewItem((Int($i / 4) + 1) & "|" & _ BitAND(GUICtrlRead($aID[$i]), $GUI_CHECKED) & "|" & _ BitAND(GUICtrlRead($aID[$i + 1]), $GUI_CHECKED) & "|" & _ BitAND(GUICtrlRead($aID[$i + 2]), $GUI_CHECKED) & "|" & _ $aID[$i + 3] & "|" & _ GUICtrlRead($aID[$i + 3]), $Listview) Next EndFunc ;==>ListViewData Func _AllCheck_Uncheck($iStart) For $j = $iStart To $aID[$Number - 8] Step 4 If BitAND(GUICtrlRead($aID[$j]), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($aID[$j], 4) ; $GUI_UNCHECKED (4) Else GUICtrlSetState($aID[$j], 1) ; $GUI_CHECKED (1) EndIf Next EndFunc ;==>_AllCheck_Uncheck Edited May 16, 2017 by Malkey Proof of concept. & Added $LVS_EX_CHECKBOXES Link to comment Share on other sites More sharing options...
KickStarter15 Posted May 16, 2017 Author Share Posted May 16, 2017 (edited) @Malkey, Sorry for the late response, just got back from vacation. Anyway, thanks for the suggestions you gave and it also helped my a lot with my current project right now its an add-on idea to my GUI. However, would it be possible to have it like this: Global $ListView = GUICtrlCreateListView("ITEMS|ELEMENTS|ERROR|NO ERROR|NA|REMARKS", 150, 200, 480, 250, Default, $LVS_EX_CHECKBOXES) For $i = 1 To 10 GUICtrlCreateListViewItem("|Title|"&, $ListView) Next Like, I want "$LVS_EX_CHECKBOXES" to be replaced with $Error[$i], $nError[$i], $NA[$i] as checkboxes? and of course, the editbox as well. I have attached a sample $Listview with what I wanted to be. Hope this helps. Kind of, something like that... Editbox in Remarks column, checkboxes are in their designed column as well. Thanks in advance. Edited May 16, 2017 by KickStarter15 Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
Malkey Posted May 16, 2017 Share Posted May 16, 2017 See my example of post #17 for non sequential control ids (all sets of checkbox and edit controls created in one "For - Next" loop) Note: The only check boxes are in the first column of the ListView. Here is a ListViewData() function for sequential control ids (each set of check boxes and edit controls created in their own loop). Note: There is one ListView control created for each column arranged next to each other horizontally. There may be another way of having multiple columns of check boxes in a ListView of which I am unaware. expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <ListViewConstants.au3> _Checkbox_EditCtrl() Func _Checkbox_EditCtrl() Local $hGUI = GUICreate("Example", 1100, 900) Global $Number = 20, $iRows = $Number, $iSpacing = 5 Global $Error[$Number] ; Array holding Checkbox controls ids Global $Edit[$Number] ; Array holding Edit controls ids ; Create checkbox controls. For $i = 0 To $Number - 1 ; id's are sequentially numbered starting at $Error[0] $Error[$i] = GUICtrlCreateCheckbox("ChkBx" & $i + 1, $iSpacing + (Int($i / $iRows) * 190), ((40 * Mod($i, $iRows)) + $iSpacing), 80, 20) ; Next ; Create Edit controls. For $i = 0 To $Number - 1 ; id's are sequentially numbered starting at $Edit[0] $Edit[$i] = GUICtrlCreateEdit("Edit" & $i + 1, $iSpacing + 80 + (Int($i / $iRows) * 190), ((40 * Mod($i, $iRows)) + $iSpacing), 95, 40, BitOR($ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL), BitOR($WS_EX_CLIENTEDGE, $WS_EX_ACCEPTFILES)) ; GUICtrlSetState($Edit[$i], $GUI_Disable) Next ListViewData() GUISetState(@SW_SHOW, $hGUI) While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop Case $Error[0] To $Error[(UBound($Error) - 1)] $Number = $msg - $Error[0] ; Array Index GUICtrlSetState($Edit[$Number], (BitAND(GUICtrlRead($Error[$Number]), $GUI_CHECKED) = $GUI_CHECKED ? BitOR($GUI_Enable, $GUI_FOCUS) : $GUI_Disable)) EndSwitch WEnd GUIDelete($hGUI) EndFunc ;==>_Checkbox_EditCtrl Func ListViewData() Local $iLeft = 400, $iWidth = 100 Local $aTitles = StringSplit("ITEMS|ELEMENTS|ERROR|NO ERROR|NA|Content of Edit", "|", 2) ; $STR_NOCOUNT (2) Local $aListview[UBound($aTitles)] ;Items $aListview[0] = GUICtrlCreateListView($aTitles[0], $iLeft, 10, $iWidth * 0.7, 500, -1, $LVS_EX_FULLROWSELECT) For $j = 0 To $Number - 1 GUICtrlCreateListViewItem($j+1, $aListview[0]) Next ; ELEMENTS|ERROR|NO ERROR|NA For $i = 1 To UBound($aTitles) - 2 $aListview[$i] = GUICtrlCreateListView($aTitles[$i], $iLeft + $i * 100, 10, $iWidth, 500, -1, $LVS_EX_CHECKBOXES) For $j = 0 To $Number - 1 GUICtrlCreateListViewItem("", $aListview[$i]) Next Next ; Content of Edit $aListview[UBound($aTitles) - 1] = GUICtrlCreateListView($aTitles[UBound($aTitles) - 1], $iLeft + ($i + 1) * 80, 10, $iWidth * 2, 500, -1, $LVS_EX_FULLROWSELECT) For $j = 0 To $Number - 1 GUICtrlCreateListViewItem(GUICtrlRead($Edit[$j]), $aListview[UBound($aTitles) - 1]) Next EndFunc ;==>ListViewData Link to comment Share on other sites More sharing options...
KickStarter15 Posted May 16, 2017 Author Share Posted May 16, 2017 49 minutes ago, Malkey said: (each set of check boxes and edit controls created in their own loop) Hmmm, I see, that is why in my searching there is no solution in creating one listview with multiple columns of checkboxes. Ok, so basically, different Listview will be created with checkboxes in it, that would be fine. But when resizing the $Listview, these $Listview() will not be tagged as one scrolling, I mean as one. Is there a way to group them as one? I know it is impossible but maybe you have any idea how. At this moment, I'm using your code in creating listview with checkboxes in every loop but I'll keep looking for solution on how they will be tagged as one scrolling (ups and downs). Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. 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