Jump to content

ComboBox Updating


Recommended Posts

I'm obviously missing something really simple here, but I have a combobox with a dropdown list that I can't seem to workout how to update it when I type in a manual answer (instead of selecting from the dropdown).

I'm using the GUIOnEventMode and the combobox updates OK when I select items from its dropdown list (because I'm using GUICtrlSetOnEvent($var,"function") to intercept a change), however, if I type something in manually nothing happens because I'm unsure how to enter the input. Do I use the Enter key or do I have to create a button next to the combobox to "set" the manual entry?

Link to comment
Share on other sites

Yeah, thats what I thought but it's still not working. This is what I'm using:

$Tyre = GUICtrlCreateCombo ( "Text",160, 40, 150)

GUICtrlSetData($Tyre,"Brand1|Brand2|Brand3","Brand1")

GUICtrlSetOnEvent($Tyre,"OnTyre")

Func OnTyre()

GUICtrlSetData($Tyre, GUICtrlRead($Tyre))

$Circumference = GUICtrlRead($Tyre)

If GUICtrlRead ($Tyre) = "Brand1" OR GUICtrlRead ($Tyre) = "Brand2" Then

$Circumference = 1.813

ElseIf GUICtrlRead ($Tyre) = "Brand3" Then

$Circumference = 1.816

EndIf

EndFunc

The problem is when I manually enter Brand4 into the combobox, unless I create a "Set value" button next to the combobox that calls the OnTyre function, any manually entered value is not passed to other functions.

I had thought pressing the enter key after placing a value into the combobox would trigger the OnEvent mode but it doesn't.

Link to comment
Share on other sites

  • Moderators

I have it entering... note the 2 msgbox debugs...

#include <guiconstants.au3>
Opt("GUIOnEventMode", 1)
GUICreate("", 400, 200)
$Tyre = GUICtrlCreateCombo ( "Text",160, 40, 150)
GUICtrlSetData($Tyre,"Brand1|Brand2|Brand3","Brand1")
GUICtrlSetOnEvent($Tyre,"OnTyre")
GUISetState()
While 1
    Sleep(100)
WEnd


Func OnTyre()
MsgBox(0, '', 'debug')
GUICtrlSetData($Tyre, GUICtrlRead($Tyre))
$Circumference = GUICtrlRead($Tyre)
MsgBox(0, "debug", $Circumference)
If GUICtrlRead ($Tyre) = "Brand1" OR GUICtrlRead ($Tyre) = "Brand2" Then
$Circumference = 1.813
ElseIf GUICtrlRead ($Tyre) = "Brand3" Then
$Circumference = 1.816
EndIf
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

I totally misread what you wrote then!!, I'm sorry.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I totally misread what you wrote then!!, I'm sorry.

Nevermind, I don't know what I was thinking - musta spent too long at the computer. In hindsight, I will have to put a "Save Settings" button on the GUI anyway so any manually entered values will be saved then.

Thanks for your replies anyway - they helped me see the error in my logic B)

Link to comment
Share on other sites

  • Moderators

Here, I felt bad for mis-reading... this may work for you. You will need the beta to run this.

#include <guiconstants.au3>
#include <misc.au3>
Opt("GUIOnEventMode", 1)
GUICreate("", 400, 200)
Dim $Tyre = GUICtrlCreateCombo ( "",160, 40, 150)
GUICtrlSetData($Tyre,"Brand1|Brand2|Brand3","")
GUISetOnEvent($GUI_EVENT_CLOSE, "EXIT_NOW")
GUISetState()
While 1
    GUICtrlSetOnEvent($Tyre,"OnTyre")
    If _IsPressed("0D") = 1 Then
        If GUICtrlRead($Tyre) = "Brand1" Or GUICtrlRead($Tyre) = "Brand2" Or GUICtrlRead($Tyre) = "Brand3" Then OnTyre()
    EndIf
    Sleep(10)
WEnd


Func OnTyre()
    GUICtrlSetData($Tyre, GUICtrlRead($Tyre))
    $Circumference = GUICtrlRead($Tyre)
    If GUICtrlRead ($Tyre) = "Brand1" OR GUICtrlRead ($Tyre) = "Brand2" Then
        $Circumference = 1.813
        MsgBox(0, '', 'CIRCUMFERENCE = ' & $Circumference)
    ElseIf GUICtrlRead ($Tyre) = "Brand3" Then
        $Circumference = 1.816
        MsgBox(0, '', 'CIRCUMFERENCE = ' & $Circumference)
    EndIf
    GUICtrlDelete($Tyre)
    $Tyre = GUICtrlCreateCombo ( "",160, 40, 150)
    GUICtrlSetData($Tyre,"Brand1|Brand2|Brand3","")
EndFunc ;==>OnTyre

Func EXIT_NOW()
    Exit
EndFunc

Edit:

All you have to do is type the name and press enter, or scroll to item and click on it.

Edited by ronsrules

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I still have the same problem.

Try this please:

#include <GuiConstants.au3>
#include <GuiCombo.au3>
#include <Misc.au3>

$dll = DllOpen("user32.dll")
Opt('MustDeclareVars',1)
dim $var
Dim $Label,$Input,$Btn_Insert,$Combo,$Btn_Exit,$msg,$Status,$i_index

GuiCreate("ComboBox Insert String", 392, 254)

$Btn_Insert = GuiCtrlCreateButton("Add String", 210, 50, 90, 30)
$Combo = GuiCtrlCreateCombo("A", 70, 100, 270, 100,$CBS_SIMPLE)
GUICtrlSetData($Combo,"B|C|D|E|F")
$Btn_Exit = GuiCtrlCreateButton("Exit", 150, 200, 90, 30)
$Status = GUICtrlCreateLabel("",0,234,392,20,BitOR($SS_SUNKEN,$SS_CENTER))

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $Btn_Exit
            ExitLoop
        Case _IsPressed("0D", $dll)
            WinActivate("ComboBox Insert String","")
            $var = ControlGetText("ComboBox Insert String", "", "Edit1")
            Sleep(200)
        ;ToolTip("_IsPressed",$var)
            $i_index = _GUICtrlComboInsertString($Combo,0,$var)
    EndSelect
WEnd
Exit
Edited by jefhal
...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
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...