Sign in to follow this  
Followers 0
DicatoroftheUSA

Auto Drop ComboBox - solved

11 posts in this topic

#1 ·  Posted (edited)

I have a gui for most buttons and checkboxes I name with "&exemple" for keyboard navigation.

I have a combo box, that when clicked on, it drops and then the user can click on an item in the list. When the user clicks on an item it takes that text and puts into an input box. Basically it lists field headers as a helper for a sqlite database syntax.

The problem is, I can set a hotkey for the input box label, it gives it focus, but it does not drop the box down. The down arrow does not cause it to drop when it has focus either, it will just select the next item in the box.

I would like it that when a hotkey is pressed to give the combobox focus, and if the down arrow is pressed, it drops down automatically,

TIA

Edited by DicatoroftheUSA

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

take a look at ContolCommand() And GUICtrlSetState() in the help file

Edited by pieeater

[spoiler]My UDFs: Login UDF[/spoiler]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

take a look at ContolCommand() And GUICtrlSetState() in the help file

It goes without saying. I did, and it didn't help. Which should go without saying, else I would not have posted. Please don't make useless replies, it wastes time; mine, yours, and everyone else who might be looking for a similar issue. If your trying to make yourself look smart by being a sarcastic smartass, you failed.

Below is an example of my script. I need it so that when in the below example, when alt+f or alt+C is pressed the respective input box drops. In the below example, clicking on the label, it does what I want it to be able to do with the keyboard. As it is, with the keyboard, it just gives focus.

#include <GUIConstantsEx.au3>
#include <ComboConstants.au3>
$loGUI=GUICreate("EXAMPLE")
 
$loInpSelect = GUICtrlCreateInput('select  * from records where scandate>' & @YEAR & @MON & @MDAY & 0000 & ' order by scandate limit 254;', 10, 10,400,200)
$loLColumn=GUICtrlCreateLabel("&Fields", 10,215)
$loComboColumns = GUICtrlCreateCombo("", 10,240,100,20,BitOr($GUI_SS_DEFAULT_COMBO, $CBS_DROPDOWNLIST))
GUICtrlSetData($loComboColumns,"EXAMPLE1")
GUICtrlSetData($loComboColumns,"EXAMPLE2")
$lolCommand=GUICtrlCreateLabel("&Compare", 120, 215)
$loComboCommands = GUICtrlCreateCombo("", 120, 240,100,20,  BitOr($GUI_SS_DEFAULT_COMBO, $CBS_DROPDOWNLIST))
GUICtrlSetData($loComboCommands,"EXAMPLE3")
GUICtrlSetData($loComboCommands,"EXAMPLE4")
GUISetState()
WHILE 1
  SWITCH GUIGetMsg()
   Case $loComboColumns
    GUICtrlSetData($loInpSelect, GUICtrlRead($loComboColumns), "test")
   Case $loComboCommands
    GUICtrlSetData($loInpSelect, GUICtrlRead($loComboCommands), "test")
   CASE $loLColumn
    ConsoleWrite("hugh")
    ControlCommand($loGUI,"",$loComboColumns,"ShowDropDown", "")
   CASE $lolCommand
    ConsoleWrite("hugh")
    ControlCommand($loGUI,"",$loComboCommands,"ShowDropDown", "")
   Case $GUI_EVENT_CLOSE
    GUIDelete($loGUI)
    ExitLoop
   EndSwitch
WEnd
Edited by DicatoroftheUSA

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

HotKeySet("^d","dropdown")

Func dropdown()

Guictrlsetstate($comboname, $GUI_FOCUS)

Send("{F4}")

otherwise check this post -

Edited by nevodj

Share this post


Link to post
Share on other sites

Send F4 will drop the combo box down

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
HotKeySet("!f", "_drop")
HotKeySet("!c", "_undrop")
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 310, 152, 361, 178)
Global $Combo1 = GUICtrlCreateCombo("Combo1", 16, 64, 145, 25)
GUICtrlSetData(-1, "i|see|this|script|works")
$Label1 = GUICtrlCreateLabel("Press Alt+f to drop the box", 16, 16, 128, 17)
$Label2 = GUICtrlCreateLabel("Press Alt+c to undrop the box", 16, 40, 143, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
 
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
 
Func _drop()
    ControlCommand("Form1", "", $Combo1, "ShowDropDown", "")
EndFunc
 
Func _undrop()
    ControlCommand("Form1", "", $Combo1, "HideDropDown", "")
EndFunc

#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 310, 152, 361, 178)
$Combo1 = GUICtrlCreateCombo("Combo1", 16, 64, 145, 25)
GUICtrlSetData(-1, "i|see|this|script|works")
$Label1 = GUICtrlCreateLabel("Press Alt+f to drop the box", 16, 16, 128, 17)
$Label2 = GUICtrlCreateLabel("Press Alt+c to undrop the box", 16, 40, 143, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
 
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    If _IsPressed(12) And _IsPressed(46) Then
        ControlCommand("Form1", "", $Combo1, "ShowDropDown", "")
    ElseIf _IsPressed(12) And _IsPressed(43) Then
        ControlCommand("Form1", "", $Combo1, "HideDropDown", "")
    EndIf
WEnd

Examples of how to use them, both ways i believe you will find work

Edited by pieeater

[spoiler]My UDFs: Login UDF[/spoiler]

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Thanks guys, what I ended up doing is below. I really like to minimize global declares, registers, and process usage, as my scripts tend to get massive. I need them to be easy enouph to read, with clearcut cause>effect chains, that neophyte coworkers can manipulate it when needed, and can eventually be turned into #includes without worry.

The problem with below, is the mouse no longer works on the combobox as expected for an end user, but that is a better problem than not having keyboard control. And worse, it forces them to select something. I know I can write a process hungry escape pattern, but I want it to be lean. I would appreciate any further tips.

#include <GUIConstantsEx.au3>
#Include <Misc.au3>
#include <ComboConstants.au3>
$loGUI = GUICreate("EXAMPLE")
 
_gui()
func _gui()
$loInpSelect = GUICtrlCreateInput('select  * from records where scandate>' & @YEAR & @MON & @MDAY & 0000 & ' order by scandate limit 254;', 10, 10, 400, 200)
$loLColumn = GUICtrlCreateLabel("&Fields", 10, 215)
$loComboColumns = GUICtrlCreateCombo("", 10, 240, 100, 20, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_DROPDOWNLIST))
GUICtrlSetData($loComboColumns, "EXAMPLE1")
GUICtrlSetData($loComboColumns, "EXAMPLE2")
$lolCommand = GUICtrlCreateLabel("&Compare", 120, 215)
$loComboCommands = GUICtrlCreateCombo("", 120, 240, 100, 20, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_DROPDOWNLIST))
GUICtrlSetData($loComboCommands, "EXAMPLE3")
GUICtrlSetData($loComboCommands, "EXAMPLE4")
GUISetState()
$loDll = DllOpen("user32.dll")
While 1
Switch GUIGetMsg()
  Case $GUI_EVENT_CLOSE
   GUIDelete($loGUI)
   ExitLoop
EndSwitch
_UnMouseCombo($loGui,$loComboColumns,$loInpSelect,$loDll )
_UnMouseCombo($loGui,$loComboCommands,$loInpSelect,$loDll )
 
WEnd
DllClose($loDll)
EndFunc
Func _UnMouseCombo($loGui,$loCombo,$loRefocus,$loDll )
WHILE 1
$X=0
If ControlGetHandle($loGUI, "", ControlGetFocus($loGUI)) = GUICtrlGetHandle($loCombo) AND $X=0 Then
  ControlCommand($loGUI,"",$loCombo,"ShowDropDown", "")
  $X=1
  If _IsPressed('0D', $loDll) Or _IsPressed('20', $loDll) Then
   ControlFocus($loGui,"",$loRefocus)
   GUICtrlSetData($loRefocus, GUICtrlRead($loRefocus)&" "&  GUICtrlRead($loCombo)&" ")
   RETURN (1)
  EndIf
else
  SetError(2)
  ControlCommand($loGUI,"",$loCombo,"HIDEDropDown", "")
  Return (-1)
  ExitLoop
EndIf
WEnd
EndFunc
Edited by DicatoroftheUSA

Share this post


Link to post
Share on other sites

the easiest way is for the user to press F4 to drop / minimize the combobox... it's a standard windows function... why complicate your script by replicating it.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

the easiest way is for the user to press F4 to drop / minimize the combobox... it's a standard windows function... why complicate your script by replicating it.

To answer your retorical question in short; it is because the drop down combo object is doesn't work as I need it to. If the solution was so simple, I wouldn't have posted. If I am not making it clear on what I am trying to accomplish, let me know how to clarify. If you are being snarky, shame on you for wasting everyones time.

What happens when they press f4, and then use the arrow keys, every time the arrow key is pressed it registers with guigetmsg() and performs the function, namely reading the value and appending it to an input box. I only want that after their selection is highlighted and press enter, or click on it. If you run the first example script, you will note this behavoir.

For some reason if I try to modify that behavior by making so that under guigetmsg=combo, if I use _ispressed is mouse click or keyboard. It doesn't run the function. Also if I just check for the enter or click event, and then check for focus, it would cause problems, as it is possible for the user to click another portion of the gui while the combobox still has focus.

I could use hotkey set, but as I stated before, I hate using global values and functions, as I intend this to be modular and used under different applications, and I would rather use a method that won't eventually cause conflicts. And ultamately I bet it is unnescessary, because I am familiar with other native windows apps that behave in the way I am trying accomplish here.

If a solution doesn't come up soon, I think I will just have to make a popup child gui. It is much uglier in script and in UI, but I am short on ideas.

Edited by DicatoroftheUSA

Share this post


Link to post
Share on other sites

Create a button that is used to activate the Combobox selection instead. This way you can scroll up and down the list as much as you want, but until you press the button, nothing gets activated. I took your script and added a button to the GUI and a message box to demonstrate one way to do it.

Func _gui()
    $loInpSelect = GUICtrlCreateInput('select  * from records where scandate>' & @YEAR & @MON & @MDAY & 0000 & ' order by scandate limit 254;', 10, 10, 400, 200)
    $loLColumn = GUICtrlCreateLabel("&Fields", 10, 215)
    $loComboColumns = GUICtrlCreateCombo("", 10, 240, 100, 20, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_DROPDOWNLIST))
    GUICtrlSetData($loComboColumns, "EXAMPLE1")
    GUICtrlSetData($loComboColumns, "EXAMPLE2")
    $lolCommand = GUICtrlCreateLabel("&Compare", 120, 215)
    $loComboCommands = GUICtrlCreateCombo("", 120, 240, 100, 20, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_DROPDOWNLIST))
    GUICtrlSetData($loComboCommands, "EXAMPLE3")
    GUICtrlSetData($loComboCommands, "EXAMPLE4")
    $Button1 = GUICtrlCreateButton("GO", 20, 300)
    GUISetState()
    $loDll = DllOpen("user32.dll")
    While 1
         Switch GUIGetMsg()
             Case $GUI_EVENT_CLOSE
                  GUIDelete($loGUI)
                  Exit
             Case $Button1
                  MsgBox(0, "", "ComboBox1 reads: " & GUICtrlRead($loComboColumns) & @CRLF & "ComboBox2 reads: " & GUICtrlRead($loComboCommands))
        EndSwitch
;~   _UnMouseCombo($loGUI, $loComboColumns, $loInpSelect, $loDll)
;~   _UnMouseCombo($loGUI, $loComboCommands, $loInpSelect, $loDll)
      WEnd
       DllClose($loDll)
EndFunc   ;==>_gui

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

@BrewManNH -Thanks, I thought of that, but for this application, it is not intuitive enouph. In nature this application going to be unavoidably too complex for its users, any multistep buttons, even clicking an extra couple buttons (ie tab+enter) will slow them down too much and cause their heads to explode.

I think I will settle with the script below, and teach them f4. Marking as solved.

#include <GUIConstantsEx.au3>
#include <ComboConstants.au3>
#include <Misc.au3>
 
Local $loComboSelection
$loGUI = GUICreate("EXAMPLE")
$loDLL = DllOpen("user32.dll")
$loInpSelect = GUICtrlCreateInput('select  * from records where scandate>' & @YEAR & @MON & @MDAY & 0000 & ' order by scandate limit 254;', 10, 10, 400, 200)
$loLColumn = GUICtrlCreateLabel("&Fields", 10, 215)
$loComboColumns = GUICtrlCreateCombo(" ", 10, 240, 100, 20, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_DROPDOWNLIST))
GUICtrlSetData($loComboColumns, "EXAMPLE1")
GUICtrlSetData($loComboColumns, "EXAMPLE2")
$lolCommand = GUICtrlCreateLabel("&Compare", 120, 215)
$loComboCommands = GUICtrlCreateCombo(" ", 120, 240, 100, 20, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_DROPDOWNLIST))
GUICtrlSetData($loComboCommands, "EXAMPLE3")
GUICtrlSetData($loComboCommands, "EXAMPLE4")
GUISetState()
 
While 1
Switch GUIGetMsg()
  Case $loComboColumns
;~  GUICtrlSetData($loInpSelect, GUICtrlRead($loComboColumns), "test")
   $loComboSelection = GUICtrlRead($loComboColumns)
   GUICtrlSetData($loComboCommands, " ")
  Case $loComboCommands
;~  GUICtrlSetData($loInpSelect, GUICtrlRead($loComboCommands), "test")
   $loComboSelection = GUICtrlRead($loComboCommands)
   GUICtrlSetData($loComboColumns, " ")
  Case $loLColumn
   ControlCommand($loGUI, "", $loComboColumns, "ShowDropDown", "")
  Case $lolCommand
   ControlCommand($loGUI, "", $loComboCommands, "ShowDropDown", "")
  Case $GUI_EVENT_CLOSE
   GUIDelete($loGUI)
   ExitLoop
EndSwitch
If WinActive($loGUI) Then
  _HandleBox($loGUI, $loComboColumns, $loInpSelect, $loDLL)
  _HandleBox($loGUI, $loComboCommands, $loInpSelect, $loDLL)
EndIf
WEnd
Sleep(100)
Func _HandleBox($loGUI, $loComboBox, $loInputBox, $loDLL)
Local $lsRead
If _GuiCtrlGetFocus($loGUI) = $loComboBox Then
If _IsPressed('01', $loDLL) Or _IsPressed('0D', $loDLL) Then
   $lhGui = GUICtrlGetHandle($loGUI)
   If GUICtrlRead($loComboBox) <> "" Then
    $lsRead = GUICtrlRead($loComboBox)
    GUICtrlSetData($loComboBox, " ")
    While _IsPressed('01', $loDLL) Or _IsPressed('0D', $loDLL)
     Sleep(1)
    WEnd
    GUICtrlSetData($loInpSelect, $lsRead, "test")
   EndIf
  EndIf
EndIf
EndFunc   ;==>_HandleBox
 
Func _GuiCtrlGetFocus($GuiRef)
Local $hwnd = ControlGetHandle($GuiRef, "", ControlGetFocus($GuiRef))
Local $result = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", $hwnd)
Return $result[0]
EndFunc   ;==>_GuiCtrlGetFocus
Edited by DicatoroftheUSA

Share this post


Link to post
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
Sign in to follow this  
Followers 0

  • Similar Content

    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning
      I'm working on a little project, and I was wondering if there's a way ( sure there is ) to insert data to a ComboBox control everytime the user insert some text in the ComboBox which is not in the ComboBox data. I'll try to explain with an example:
      - Form with some data ( ComboBox is empty );
      - User prompt something in the ComboBox: if what the user prompts is not in the ComboBox values ( at the moment empty ), then insert the value in the ComboBox values, in order to have, next time the user prompts the form, the value that he entered.
      More pratical example:
      - First call of the form, ComboBox empty;
      - I prompt "A" in the ComboBox;
      - Second call, in the ComboBox I should see "A";
      - I prompt "B" in the ComboBox;
      - Third call, I should see "A"
                                                 "B";
      - And so on...
      Everytime the form is called, I re-create it, so I think I can't use _GUICtrlComboBox_AddStrings().
      I tried with
      Global $strCboStrings = "" ; When the user prompt the form, the code below is executed. ; I.E. : User prompt "A", after the if I should have "A"; ; In the second call, If I write "B", I should see "A" ; "B"; ; If I write "A" again, in the combobox values should not be any changes. If Not StringInStr($strCboStrings, GUICtrlRead($cboVoiceCategory)) <> 0 Then $strCboStrings &= $strCboStrings & "|" & GUICtrlRead($cboVoiceCategory) EndIf Any suggestion?
      Thanks
    • kstriyhon
      By kstriyhon
      hello Comunity i am new to autoit and i bump into a pitfall regarding the creation of objects in a dinamyc way but more especific  creating combobox at runtime
      i need many comboboxes and sofar i createdthem manually 
      like this 
      $idCombo_1 = GUICtrlCreateCombo("", 500, 40, 130, 21)     $idCombo_2 = GUICtrlCreateCombo("", 500, 70, 130, 21)     $idCombo_3 = GUICtrlCreateCombo("", 500, 100, 130, 21)     $idCombo_4 = GUICtrlCreateCombo("", 500, 130, 130, 21)     $idCombo_5 = GUICtrlCreateCombo("", 500, 160, 130, 21)     $idCombo_6 = GUICtrlCreateCombo("", 500, 190, 130, 21)     $idCombo_7 = GUICtrlCreateCombo("", 500, 220, 130, 21)     $idCombo_8 = GUICtrlCreateCombo("", 500, 250, 130, 21)     $idCombo_9 = GUICtrlCreateCombo("", 500, 280, 130, 21)     GUICtrlSetData($idCombo_1, "Item1|Item2|Item3|Item4|Item5")     GUICtrlSetData($idCombo_2, "Item1|Item2|Item3|Item4|Item5")     GUICtrlSetData($idCombo_3, "Item1|Item2|Item3|Item4|Item5")     GUICtrlSetData($idCombo_4, "Item1|Item2|Item3|Item4|Item5")     GUICtrlSetData($idCombo_5, "Item1|Item2|Item3|Item4|Item5")     GUICtrlSetData($idCombo_6, "Item1|Item2|Item3|Item4|Item5")     GUICtrlSetData($idCombo_7, "Item1|Item2|Item3|Item4|Item5")     GUICtrlSetData($idCombo_8, "Item1|Item2|Item3|Item4|Item5")     GUICtrlSetData($idCombo_9, "Item1|Item2|Item3|Item4|Item5") now i need this example but create them at runtime as there are more than 9 combos what i need thanks in advance kind regards
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening guys
      I am working on a little project, in which I have to retrieve 8000+ rows of data from a table, from a SQLite database, to populate a combobox 
      This is what I tried 'til now, but it still takes about 12 seconds to populate the combobox.
      _SQLite_Exec($objDatabase, "BEGIN TRANSACTION;") If _SQLite_GetTable($objDatabase, "SELECT DISTINCT Comune FROM LISTA_COMUNI;", $arrRisultatoQuery, $intRighe, $intColonne) = $SQLITE_OK Then For $i = 2 To UBound($arrRisultatoQuery) - 1 If $i < UBound($arrRisultatoQuery) - 1 Then GUICtrlSetData($cbo_ComuneNascita, $arrRisultatoQuery[$i] & "|") Else GUICtrlSetData($cbo_ComuneNascita, $arrRisultatoQuery[$i]) EndIf Next _SQLite_Exec($objDatabase, "COMMIT;") Are there any other solution to retrieve 8000+ records from a SQLite database?
      Thank you very much  
    • satanico64
      By satanico64
      Hi huys !
       how are you ? family ? dog, cat ? well..
       
      I've got a problem: _GUICtrlComboBox_GetCueBanner
      i can't get it to work.
      Simple: even the example from help does'nt work...
       
      I insist, it's excactly the example from the help, no modifications
      #include <GuiComboBox.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $g_idMemo Example() Func Example() Local $idCombo ; Create GUI GUICreate("ComboBox Get Count", 400, 296) $idCombo = GUICtrlCreateCombo("", 2, 2, 396, 296) _GUICtrlComboBox_SetCueBanner($idCombo, "Select an Item") $g_idMemo = GUICtrlCreateEdit("", 10, 50, 376, 234, $WS_VSCROLL) GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New") GUISetState(@SW_SHOW) ; Add files _GUICtrlComboBox_BeginUpdate($idCombo) _GUICtrlComboBox_AddDir($idCombo, @WindowsDir & "\*.exe") _GUICtrlComboBox_EndUpdate($idCombo) MemoWrite("Cue Banner: " & _GUICtrlComboBox_GetCueBanner($idCombo)) ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example ; Write a line to the memo control Func MemoWrite($sMessage) GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1) EndFunc ;==>MemoWrite I also added the display of the cuebanner in the loop.
      It never display what actually appears in the combo
      If you can show me any king of working example.
      Thanks Guys !
      Nicolas.
      Actually autoit v3.3.14.2
    • Terenz
      By Terenz
      Hello,
      I have searched everywhere but on the forum there isn't an example of a combobox with checkbox. I think is a very useful control but require subclassing. Several example in C++, one of this:
      CheckComboBox Control
      If somone has some time to check it out. If need i can provide the source code. Thanks