Netol Posted December 15, 2024 Posted December 15, 2024 mi my friend, Just to ask how update combo automatically after change a value i have this code $Combo_template1 = GUICtrlCreateCombo(1, 280, 170, 50, 21) GUICtrlSetData($Combo_template1, "2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48") and i have the code to detect changes case $Combo_template1 $id_template = GUICtrlRead($Combo_template1) the problem is when i send keys with paste or i write a value the case $Combo_template1 not work this code work only when i select the value of the scroll list How can I add a code so that when I type a value or paste a value it goes through validation? case $Combo_template1 $id_template = GUICtrlRead($Combo_template1) best regards
ahmet Posted December 15, 2024 Posted December 15, 2024 Hi, do you need something like following expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Example() Func Example() Global $sPreviousSelection="";new variable that holds info about last selection ; Create a GUI with various controls. Local $hGUI = GUICreate("Example", 300, 200) ; Create a combobox control. Local $idComboBox = GUICtrlCreateCombo("Item 1", 10, 10, 185, 20) Local $idButton_Close = GUICtrlCreateButton("Close", 210, 170, 85, 25) ; Add additional items to the combobox. GUICtrlSetData($idComboBox, "Item 2|Item 3", "Item 2") ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) Local $sComboRead = "" ; Loop until the user exits. $sPreviousSelection=GUICtrlRead($idComboBox);update variable with the currently selected item While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idButton_Close ExitLoop Case $idComboBox $sComboRead = GUICtrlRead($idComboBox) ;MsgBox($MB_SYSTEMMODAL, "", "The combobox is currently displaying: " & $sComboRead, 0, $hGUI) If $sComboRead<>$sPreviousSelection Then MsgBox(0,"Combobox","Selection changed") $sPreviousSelection=$sComboRead EndIf EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>Example When you ask for help it would be good to post runnable code.
Dan_555 Posted December 15, 2024 Posted December 15, 2024 (edited) This would add typed items into the combo box whenever something is typed/pasted after a certain amount of time. The timer starts new whenever the data is different, and when it runs out, it writes the data into the combo box. Currently i have set the timer on 2 seconds. I took the base code from https://www.autoitscript.com/forum/topic/190196-add-element-in-a-combobox-if-its-not-in-the-combobox-data/ and added the timing functions. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> ; Create a Global variable to hold the combo data Global $sComboData = "" Global $hGui, $Cco, $cAdd $hGui = GUICreate("test ", 250, 100, -1, -1, $GUI_SS_DEFAULT_GUI) ; Create combo and load with saved data $Cco = GUICtrlCreateCombo("", 10, 10, 200, 20) GUICtrlSetData($Cco, $sComboData) ; Create a button to add new data $cAdd = GUICtrlCreateButton("Add", 10, 50, 80, 30) GUISetState() $oldC = GUICtrlRead($Cco) $Ctimer = TimerInit() $ccw = 0 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $cAdd ; Add new data to the combo _AddComboData() $oldC = GUICtrlRead($Cco) $ccw = 0 Case $Cco ; Just to show that the data is selectable $ccw = 0 $oldC = GUICtrlRead($Cco) ConsoleWrite("Selected " & $oldC) EndSwitch If $oldC <> GUICtrlRead($Cco) Then $oldC = GUICtrlRead($Cco) ConsoleWrite("Data is different" & @CRLF) $Ctimer = TimerInit() $ccw = 1 EndIf If TimerDiff($Ctimer) > 2000 Then If $ccw > 0 Then ConsoleWrite("Writing data to the combo box" & @CRLF) _AddComboData() $oldC = GUICtrlRead($Cco) $ccw = 0 EndIf EndIf WEnd Func _AddComboData() ; Read the content of the combo edit $sComboSel = GUICtrlRead($Cco) ; Check if in saved data If Not StringInStr($sComboData, "|" & $sComboSel) Then ; If not then add to saved data and load into the combo $sComboData &= "|" & $sComboSel GUICtrlSetData($Cco, $sComboData) EndIf EndFunc ;==>_AddComboData Edited December 15, 2024 by Dan_555 typo Netol 1 Some of my script sourcecode
ioa747 Posted December 15, 2024 Posted December 15, 2024 Here is my contribution expandcollapse popup#include <MsgBoxConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Example() Func Example() ; Create a GUI with various controls. Local $hGUI = GUICreate("Example", 300, 200) Local $Template1 = "1" Local $Combo_template1 = GUICtrlCreateCombo($Template1, 10, 10, 185, 20) Local $Button_Close = GUICtrlCreateButton("Close", 210, 170, 85, 25) Local $Button_Add1 = GUICtrlCreateButton("Set +1", 10, 170, 85, 25) GUICtrlSetData($Combo_template1, "2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48") GUISetState(@SW_SHOW, $hGUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $Button_Close ExitLoop Case $Button_Add1 Local $Val = Int(GUICtrlRead($Combo_template1)) GUICtrlSetData($Combo_template1, $Val >= 48 ? 48 : $Val + 1) Case $Combo_template1 ConsoleWrite("$Combo_template1=" & GUICtrlRead($Combo_template1) & @CRLF) EndSwitch If $Template1 <> GUICtrlRead($Combo_template1) Then $Template1 = GUICtrlRead($Combo_template1) ConsoleWrite("$Template1=" & $Template1 & @CRLF) EndIf WEnd GUIDelete($hGUI) EndFunc ;==>Example Netol 1 I know that I know nothing
Nine Posted December 15, 2024 Posted December 15, 2024 Or based on notification : expandcollapse popup#include <WinAPIConv.au3> #include <GUIConstants.au3> #include <Constants.au3> Global $idComboBox Example() Func Example() Local $hGUI = GUICreate("Example", 300, 200) $idComboBox = GUICtrlCreateCombo("1", 10, 10, 185, 20) Local $idButton_Close = GUICtrlCreateButton("Close", 210, 170, 85, 25) GUICtrlSetData($idComboBox, "2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48") GUISetState() GUIRegisterMsg($WM_COMMAND, WM_COMMAND) While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idButton_Close ExitLoop EndSwitch WEnd EndFunc ;==>Example Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) Local $idCtrl = _WinAPI_LoWord($wParam), $iCode = _WinAPI_HiWord($wParam) If $idCtrl = $idComboBox And ($iCode = $CBN_KILLFOCUS Or $iCode = $CBN_SELCHANGE) Then DoSomething($idCtrl) Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND Func DoSomething($idComboBox) Local Static $sSelection Local $sComboRead = GUICtrlRead($idComboBox) If $sSelection <> $sComboRead Then If GUICtrlSendMsg($idComboBox, $CB_FINDSTRINGEXACT, -1, $sComboRead) = -1 Then GUICtrlSendMsg($idComboBox, $CB_SETCURSEL, -1, 0) $sSelection = "" ConsoleWrite("Invalid data" & @CRLF) Else $sSelection = $sComboRead ConsoleWrite("The combobox is currently displaying: " & $sComboRead & @CRLF) EndIf EndIf EndFunc ;==>DoSomething Netol 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Netol Posted December 15, 2024 Author Posted December 15, 2024 9 hours ago, ahmet said: Hi, do you need something like following expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Example() Func Example() Global $sPreviousSelection="";new variable that holds info about last selection ; Create a GUI with various controls. Local $hGUI = GUICreate("Example", 300, 200) ; Create a combobox control. Local $idComboBox = GUICtrlCreateCombo("Item 1", 10, 10, 185, 20) Local $idButton_Close = GUICtrlCreateButton("Close", 210, 170, 85, 25) ; Add additional items to the combobox. GUICtrlSetData($idComboBox, "Item 2|Item 3", "Item 2") ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) Local $sComboRead = "" ; Loop until the user exits. $sPreviousSelection=GUICtrlRead($idComboBox);update variable with the currently selected item While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idButton_Close ExitLoop Case $idComboBox $sComboRead = GUICtrlRead($idComboBox) ;MsgBox($MB_SYSTEMMODAL, "", "The combobox is currently displaying: " & $sComboRead, 0, $hGUI) If $sComboRead<>$sPreviousSelection Then MsgBox(0,"Combobox","Selection changed") $sPreviousSelection=$sComboRead EndIf EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>Example When you ask for help it would be good to post runnable code. Thanks for your responce. when you write a value in the combo and the press enter or tab the code not working
Solution ahmet Posted December 15, 2024 Solution Posted December 15, 2024 Then most probably solution from @Dan_555 will work for you. Netol 1
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