Jump to content

How to make ComboBox accept manual input?


altex
 Share

Go to solution Solved by Melba23,

Recommended Posts

Hello,

I just come across a new problem. I create a combo box with following scripts

#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 by altex
Link to comment
Share on other sites

  • Moderators

altex,

Set {ENTER} as an Accelerator key and check if the combo has focus when it is pressed: ;)

#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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

altex,

Set {ENTER} as an Accelerator key and check if the combo has focus when it is pressed: ;)

#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 by altex
Link to comment
Share on other sites

  • Moderators

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. :)

M23

P.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. ;)

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators
  • Solution

altex,

Perhaps like this: :)

#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   ;==>_ComboRead
M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...