Page 1 sur 1

Checkbox dynamiques et $gui_uncheck

Posté : jeu. 06 oct. 2022 10:16
par Ciol13
Bonjour à tous, je suis complètement bloqué là, j'ai écrit un code qui fonctionne, par contre, j'aimerais l'améliorer, et là, je bloque :
je construit des checkbox de manière dynamiques, et je voudrais, par exemple, toute les décocher en appuyant sur le bouton annuler.
je retrouve bien le handle de ma checkbox, mais avec la commande
$Controle = GUICtrlGetHandle (Eval("Checkboxoui"&$i))
guictrlsetstate($Controle,$gui_unchecked)
ça ne fait rien

en gros, toutes les parties commentées ;***************** ne fonctionnent pas, so...

voici mon code

Code : Tout sélectionner

#include <Array.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <File.au3>
#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WinAPIFiles.au3>
#include <WindowsConstants.au3>

local const $iniFileConf=@ScriptDir & "\Config.ini"
local const $iniFileForm=@ScriptDir & "\formations.ini"
local const $iniFileDispo=@ScriptDir & "\dispo.ini"
Local $hFile = FileOpen(@ScriptDir & "\TrcFct.log", 1)

#Region ### START Koda GUI section ### Form=
$Disponibilite = GUICreate("Disponibilités FPDM1", 615, 437, 192, 124)
$Combo1 = GUICtrlCreateCombo("", 24, 13, 161, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))

$Section="REGIONS"
$aArray=IniReadSection($iniFileConf, $Section)
If Not @error Then
; Enumerate through the array displaying the keys and their respective values.
   For $i = 1 To $aArray[0][0]
	  GUICtrlSetData($Combo1,$aArray[$i][1])
   Next
EndIf

$Combo2 = GUICtrlCreateCombo("", 24, 40, 161, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetState(-1, $GUI_HIDE)

$Button1 = GUICtrlCreateButton("valider", 488, 392, 105, 33)
$Button2 = GUICtrlCreateButton("Annuler", 352, 392, 113, 33)


GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		 Case $GUI_EVENT_CLOSE
			Exit
		 case $Combo1
			$Section= GUICtrlRead($Combo1)
			$aArray=IniReadSection($iniFileConf, $Section)
			If Not @error Then
			; Enumerate through the array displaying the keys and their respective values.
			   For $i = 1 To $aArray[0][0]
				  GUICtrlSetData($Combo2,$aArray[$i][1])
			   Next
			EndIf
			GUICtrlSetState($Combo2, $GUI_show)
		 case $combo2
			$FTP=GUICtrlRead($combo2)
			_FileWriteLog($hFile, $FTP & " - " & $Section, -1)

			$Label1 = GUICtrlCreateLabel("Formation FPDM1 Promo :", 40, 95, 300, 20)
			$Label2 = GUICtrlCreateLabel("Disponible", 400, 95, 100, 20)

			$aArray=IniReadSection($iniFileForm, "Promotion" & @YEAR+1)
			$n = $aArray[0][0]
			If Not @error Then
			; Enumerate through the array displaying the keys and their respective values.
			   For $i = 1 To  $n
				  $y=95+($i*20)
				  $Label = GUICtrlCreateLabel($aArray[$i][1] ,40, $y, 340, 20)
				  Assign("Checkboxoui" & $i, GUICtrlCreateCheckbox("Oui" ,400, $y, 50, 20))
			   Next
			EndIf
			$m=$n
			$Label = GUICtrlCreateLabel("Formation FPDM1 HORS Promo :" ,40, 95+$y, 340, 20)
			$aArray=IniReadSection($iniFileForm, "Hors_Promotion" & @YEAR+1)
			$n = $aArray[0][0]
			If Not @error Then
			; Enumerate through the array displaying the keys and their respective values.
			   For $i = 1 To  $n
				  $z =95+$y+($i*20)
				  $Label = GUICtrlCreateLabel($aArray[$i][1] ,40, $z, 340, 20)
				  Assign("Checkboxoui" & $i + $m, GUICtrlCreateCheckbox("Oui" ,400, $z, 50, 20))
			   Next
			EndIf
			$m=$m+$n

			For $i= 1 to $m
			   $aArray=IniReadSection($iniFileDispo, $i & "_" & @YEAR+1)
			   $ii = $aArray[0][0]
			   For $t = 1 to $ii
				  If $FTP = $aArray[$t][1] Then
					 guictrlsetstate("Checkboxoui"&$t,$gui_checked);*****************
				  EndIf
			   Next
			next

		 case $Button1
			for $i = 1 to $m
			   if GUICtrlRead(Eval("Checkboxoui"&$i)) = 1 then
				  $aArray=IniReadSection($iniFileDispo, $i & "_" & @YEAR+1)
				  IniWrite($iniFileDispo,$i & "_" & @YEAR+1, $aArray[0][0]+1, $FTP)
			   EndIf
			next
			msgbox ("", "", "Merci pour votre réponse")
			Exit
		 case $Button2
			for $i = 1 to $m;
			   if GUICtrlRead(Eval("Checkboxoui"&$i)) = 1 then;*****************
				  $Controle = GUICtrlGetHandle (Eval("Checkboxoui"&$i));*****************
				  guictrlsetstate($Controle,$gui_unchecked);*****************
			   EndIf
			Next

	EndSwitch
WEnd

Mon code est probablement brouillon, et pas forcément bien construit, mais il fonctionne, en revanche, si vous avez des propositions d'amélioration, moi je suis preneur, c'est toujours bon d'apprendre

Re: Checkbox dynamiques et $gui_uncheck

Posté : jeu. 06 oct. 2022 12:05
par jpascal
Plutôt que d'utiliser la fonction Assign(), je te conseille la création d'un tableau.
Global $g_aidCheckboxoui[0]

Remplace :
Assign("Checkboxoui" & $i + $m, GUICtrlCreateCheckbox("Oui" ,400, $z, 50, 20))
par
_ArrayAdd($g_aidCheckboxoui, GUICtrlCreateCheckbox("Oui" ,400, $z, 50, 20))

Il suffit ensuite de parcourir le tableau pour changer l'état des contrôles.

Re: Checkbox dynamiques et $gui_uncheck

Posté : mer. 12 oct. 2022 09:10
par mikell
C'est vrai qu'il vaut mieux utiliser un tableau...

Le GUICtrlGetHandle est de trop
$Controle = Eval("Checkboxoui"&$i)
guictrlsetstate($Controle, $gui_unchecked)
Pour en dire plus il faudrait poster aussi le fichier ini