altex Posted September 26, 2014 Share Posted September 26, 2014 (edited) Hello, I just come across a new problem. I create a combo box with following scripts expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Example() Func Example() ; Create a GUI with various controls. Local $hGUI = GUICreate("Example", 300, 200) ; Create a combobox control. Local $idComboBox = GUICtrlCreateCombo("10", 10, 10, 185, 20) Local $idClose = GUICtrlCreateButton("Close", 210, 170, 85, 25) ; Add additional items to the combobox. GUICtrlSetData($idComboBox, "20|30", "20") ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) Local $sComboRead = "" ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idClose ExitLoop Case $idComboBox $sComboRead = GUICtrlRead($idComboBox) MsgBox($MB_SYSTEMMODAL, "", "The combobox is currently displaying: " & $sComboRead, 0, $hGUI) EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>Example I notice I can also input something into the comboBox. So my question is how to make the comboBox accepts my inputs although the value I entered is not in the list? For example, in the example I gave, the comboBox has three entries in the list 10,20,30. How can I make the comboBox accepts other value (or pass this new value to the variable associated to comboBox), let's say 25, when I enter 25 in that comboBox then hit "Enter"? Thanks. Edited September 26, 2014 by altex Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 26, 2014 Moderators Share Posted September 26, 2014 altex,Set {ENTER} as an Accelerator key and check if the combo has focus when it is pressed: expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <GuiComboBox.au3> Example() Func Example() ; Create a GUI with various controls. Local $hGUI = GUICreate("Example", 300, 200) ; Create a combobox control. Local $idComboBox = GUICtrlCreateCombo("10", 10, 10, 185, 20) ; Add additional items to the combobox. GUICtrlSetData($idComboBox, "20|30", "20") ; Get handle of combo edit <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Local $tInfo _GUICtrlComboBox_GetComboBoxInfo($idComboBox, $tInfo) $hEdit = DllStructGetData($tInfo, "hEdit") Local $idClose = GUICtrlCreateButton("Close", 210, 170, 85, 25) ; Create a dummy control $cEnter = GUICtrlCreateDummy() ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) Local $sComboRead = "" ; Set ENTER as an Accelerator key <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Local $aAccelKeys[1][2] = [["{ENTER}", $cEnter]] GUISetAccelerators($aAccelKeys) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idClose ExitLoop Case $cEnter ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ; Check if combo edit has focus If _WinAPI_GetFocus() = $hEdit Then ContinueCase EndIf Case $idComboBox $sComboRead = GUICtrlRead($idComboBox) MsgBox($MB_SYSTEMMODAL, "", "The combobox is currently displaying: " & $sComboRead, 0, $hGUI) EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>ExamplePlease ask if anything is unclear. M23 altex 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
altex Posted September 26, 2014 Author Share Posted September 26, 2014 (edited) altex, Set {ENTER} as an Accelerator key and check if the combo has focus when it is pressed: expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <GuiComboBox.au3> Example() Func Example() ; Create a GUI with various controls. Local $hGUI = GUICreate("Example", 300, 200) ; Create a combobox control. Local $idComboBox = GUICtrlCreateCombo("10", 10, 10, 185, 20) ; Add additional items to the combobox. GUICtrlSetData($idComboBox, "20|30", "20") ; Get handle of combo edit <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Local $tInfo _GUICtrlComboBox_GetComboBoxInfo($idComboBox, $tInfo) $hEdit = DllStructGetData($tInfo, "hEdit") Local $idClose = GUICtrlCreateButton("Close", 210, 170, 85, 25) ; Create a dummy control $cEnter = GUICtrlCreateDummy() ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) Local $sComboRead = "" ; Set ENTER as an Accelerator key <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Local $aAccelKeys[1][2] = [["{ENTER}", $cEnter]] GUISetAccelerators($aAccelKeys) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idClose ExitLoop Case $cEnter ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ; Check if combo edit has focus If _WinAPI_GetFocus() = $hEdit Then ContinueCase EndIf Case $idComboBox $sComboRead = GUICtrlRead($idComboBox) MsgBox($MB_SYSTEMMODAL, "", "The combobox is currently displaying: " & $sComboRead, 0, $hGUI) EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>Example Please ask if anything is unclear. M23 Thanks, M23,. you solved my problem again. Could you tell which function can be used to check if the input is "numbers" and the input number is within certain range, say >0 and <100? Edited September 26, 2014 by altex Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 26, 2014 Moderators Share Posted September 26, 2014 altex,The return you get from the combo is a string, so use Number to convert it to numeric format (only leading digits are considered valid). Then use Switch structure to set the bounds. M23P.S. When you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - I know what I wrote and it just pads the thread unnecessarily. Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
altex Posted September 26, 2014 Author Share Posted September 26, 2014 OK, got it. thanks. Link to comment Share on other sites More sharing options...
altex Posted September 26, 2014 Author Share Posted September 26, 2014 Hello M23, Could you suggest how to extend the example code you posted earlier to the case of two individual combo Box? They work individually and both are able to accept manual inputs when "Enter" is hit? Thanks. Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted September 26, 2014 Moderators Solution Share Posted September 26, 2014 altex,Perhaps like this: expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <GuiComboBox.au3> Example() Func Example() ; Create a GUI with various controls. Local $hGUI = GUICreate("Example", 300, 200) GUICtrlCreateLabel("Combo 1", 10, 10, 200, 20) Local $idComboBox_1 = GUICtrlCreateCombo("10", 10, 30, 185, 20) ; Add additional items to the combobox. GUICtrlSetData($idComboBox_1, "20|30", "20") GUICtrlCreateLabel("Combo 2", 10, 70, 200, 20) Local $idComboBox_2 = GUICtrlCreateCombo("10", 10, 90, 185, 20) GUICtrlSetData($idComboBox_1, "20|30", "20") ; Get handles of combo edits Local $tInfo _GUICtrlComboBox_GetComboBoxInfo($idComboBox_1, $tInfo) $hEdit_1 = DllStructGetData($tInfo, "hEdit") _GUICtrlComboBox_GetComboBoxInfo($idComboBox_2, $tInfo) $hEdit_2 = DllStructGetData($tInfo, "hEdit") Local $idClose = GUICtrlCreateButton("Close", 210, 170, 85, 25) ; Create a dummy control $cEnter = GUICtrlCreateDummy() ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) Local $sComboRead = "" ; Set ENTER as an Accelerator key Local $aAccelKeys[1][2] = [["{ENTER}", $cEnter]] GUISetAccelerators($aAccelKeys) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idClose ExitLoop Case $cEnter Switch _WinAPI_GetFocus() Case $hEdit_1 _ComboRead(1, $idComboBox_1, $hGUI) Case $hEdit_2 _ComboRead(2, $idComboBox_2, $hGUI) EndSwitch Case $idComboBox_1 _ComboRead(1, $idComboBox_1, $hGUI) Case $idComboBox_2 _ComboRead(2, $idComboBox_2, $hGUI) EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>Example Func _ComboRead($iID, $cCombo, $hGUI) $sComboRead = GUICtrlRead($cCombo) MsgBox($MB_SYSTEMMODAL, "Combo " & $iID, "Combo " & $iID & " is currently displaying: " & $sComboRead, 0, $hGUI) EndFunc ;==>_ComboReadM23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
altex Posted September 26, 2014 Author Share Posted September 26, 2014 thanks a lot, M23. Your answer is very inspiring. 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