Page 1 sur 1
[R] Combobox détection du changement (onchange)
Posté : jeu. 25 juin 2009 09:29
par lord1366
Bonjour,
Je voudrais détecter le changement de choix dans un select ou combobox (comme un onchange en javascript)
J'arrive à récupérer le contenu de $BtChoixType avec GUICtrlRead($ComboBoxType)
Ce que je voudrais c'est que si je change de choix pour Local ou pour le 2ème index alors le contenu d'un autre champs soit modifié.
Code : Tout sélectionner
;Menu deroulant
$BtChoixType = GUICtrlSetData($ComboBoxType, "Distant|Local","Distant")
GUICtrlSetOnEvent($BtChoixType, "test")
;Input a modifier
$AddrServeur = GuiCtrlCreateInput($Server & ":" & $Port,345, 10, 150, 21,$ES_READONLY)
Merci pour votre aide.
Re: [..] Combobox détection du changement (onchange)
Posté : jeu. 25 juin 2009 11:42
par jumby
Pour détecter le changement de choix dans un combobox, le plus simple est de passer par la bonne vieille fonction case.
Voici comment vous-y prendre pour détecter le changement de choix pour Local :
Code : Tout sélectionner
Case $ComboBoxType
$ComboBoxReadValue = GUICtrlRead($ComboBoxType)
If $ComboBoxReadValue = "Local" Then
call ("Localisselect")
EndIf
La fonction Localisselect sera exécutée lorsque Local sera sélectionné, à vous de garnir votre fonction pour changer votre Input en conséquence.
Re: [..] Combobox détection du changement (onchange)
Posté : jeu. 25 juin 2009 13:08
par Iste
heu sinon
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
Opt('MustDeclareVars', 1)
Example()
Func Example()
Local $msg
GUICreate("My GUI combo") ; will create a dialog box that when displayed is centered
GUICtrlCreateCombo("item1", 10, 10) ; create first item
GUICtrlSetData(-1, "item2|item3", "item3") ; add other item snd set a new default
GUISetState()
; Run the GUI until the dialog is closed
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
EndFunc ;==>Example
pas facile a trouver faut dire, c'est bien caché dans la doc :p
donc, GUIGetMsg() renvoi l'ID de la combobox quand on l'utilise, comme pour tout les autre control
ou bien
Code : Tout sélectionner
Opt("GUIOnEventMode", 1)
$combobox = GUICtrlCreateCombo("item1", 10, 10)
GUICtrlSetOnEvent($combobox, "fonction")
Re: [..] Combobox détection du changement (onchange)
Posté : ven. 26 juin 2009 00:05
par orax
http://msdn.microsoft.com/en-us/library ... S.85).aspx► Afficher le textepour voir une solution alternative
Code : Tout sélectionner
#include <GuiComboBoxEx.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <WinAPI.au3>
Opt('MustDeclareVars', 1)
Global $hGUI, $combo, $hCombo
$hGUI = GUICreate("ComboBoxEx Create", 400, 300)
$combo = GUICtrlCreateCombo("item1", 10, 10) ; create first item
$hCombo = GUICtrlGetHandle($combo)
GUISetState()
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg
Local $hWndFrom, $iIDFrom, $iCode
$hWndFrom = $ilParam
$iIDFrom = _WinAPI_LoWord($iwParam)
$iCode = _WinAPI_HiWord($iwParam)
Switch $hWndFrom
Case $hCombo
Switch $iCode
Case $CBN_EDITUPDATE ; Sent after the user has taken an action that may have altered the text in the edit control portion of a combo box
ConsoleWrite("$CBN_EDITUPDATE" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
Case $CBN_SELCHANGE ; Sent after the user has taken an action that may have altered the text in the edit control portion of a combo box
ConsoleWrite("$CBN_SELCHANGE" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
EndSwitch
EndSwitch
EndFunc ;==>WM_COMMAND

Re: [..] Combobox détection du changement (onchange)
Posté : ven. 26 juin 2009 09:37
par lord1366
Bonjour,
Merci pour votre aide, erreur de ma part, vous avez raison.
Code : Tout sélectionner
Erreur :
$ComboBoxType = GUICtrlCreateCombo("", 260, 10,75)
[color=#BF0000]$ChoixType[/color] = GUICtrlSetData($ComboBoxType, "Distant|Local","Distant")
GUICtrlSetOnEvent([color=#BF0000]$ChoixType[/color], "ChangeType")
Solution
[color=#00FF00]$ComboBoxType[/color] = GUICtrlCreateCombo("", 260, 10,75)
$GUICtrlSetData($ComboBoxType, "Distant|Local","Distant")
GUICtrlSetOnEvent([color=#00FF00]$ComboBoxType[/color], "ChangeType")