Jump to content

Prevent combo from updating before user selects a item in it


TheDcoder
 Share

Recommended Posts

Hello :bye:, I am experiencing a problem with Combo controls... They get updated even before the user selects the item! Use this script to test this:

#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 366, 115, 301, 138)
$Combo1 = GUICtrlCreateCombo("Combo1", 104, 24, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUICtrlSetData($Combo1, "Test")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
    ConsoleWrite(GUICtrlRead($Combo1) & @CRLF)
WEnd

Try hovering over "Test" (don't select it!) and watch the STDOUT stream (SciTE Output Panel located at the bottom of SciTE), it shows "Test" instead of "Combo1" :(

 

Anyone know how to avoid this? Thanks in Advance, TD :)

Edited by TheDcoder

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

  • Moderators

TheDcoder,

Use a CueBanner like this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiComboBox.au3>

$hGUI = GUICreate("Test", 500, 500)
$cCombo = GUICtrlCreateCombo("", 10, 10, 200, 25)
GUICtrlSetData($cCombo, "Test")
_GUICtrlComboBox_SetCueBanner($cCombo, "Combo1")

$cButton = GUICtrlCreateCheckbox("Test", 10, 100, 80, 30)
GUICtrlSetState($cButton, $GUI_FOCUS)

GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch



    If GUICtrlRead($cCombo) Then
        ConsoleWrite(GUICtrlRead($cCombo) & @CRLF)
    EndIf
WEnd

You need the button because the CueBanner is only visible when the combo does not have focus.

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

You can try something like this:

#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListBox.au3>
Global $bSelChanged = True

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 366, 115, 301, 138)
$Combo1 = GUICtrlCreateCombo("Combo1", 104, 24, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData($Combo1, "Test")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
    If $bSelChanged Then
      ConsoleWrite(GUICtrlRead($Combo1) & @CRLF)
      $bSelChanged = False
    EndIf
WEnd

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
  #forceref $hWnd, $iMsg
  Local $hWndFrom, $iIDFrom, $iCode, $hWndListBox
  ;If Not IsHWnd($g_hListBox) Then $hWndListBox = GUICtrlGetHandle($g_hListBox)
  $hWndFrom = $lParam
  $iIDFrom = BitAND($wParam, 0xFFFF) ; Low Word
  $iCode = BitShift($wParam, 16) ; Hi Word

  ;Switch $hWndFrom
    ;Case $g_hListBox, $hWndListBox
      Switch $iCode
        Case $LBN_SELCHANGE ; Sent when the selection in a list box has changed
          $bSelChanged = True
          ; no return value
      EndSwitch
  ;EndSwitch
  Return $GUI_RUNDEFMSG
EndFunc

 

Link to comment
Share on other sites

  • Moderators

TheDcoder,

If all you want is to read the combo when it changes than just set a case for it:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("Test", 500, 500)
$cCombo = GUICtrlCreateCombo("", 10, 10, 200, 25)
GUICtrlSetData($cCombo, "Combo1|Test", "Combo1")

GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cCombo

            ConsoleWrite(GUICtrlRead($cCombo) & @CRLF)
    EndSwitch
WEnd

You really do need to give more explanation of what you require when you post - far too often lately you have just thrown out a snippet and expected the community to work out what it is that you want to happen. Explaining in more detail means that others will not waste their time posting possible solutions which turn out not to be what you require.

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

@LarsJ Thanks for the solution but M23's solution seems better, sorry! :sweating:

@Melba23 That was astonishingly simple :shocked:, Thanks! :)

You really do need to give more explanation of what you require when you post - far too often lately you have just thrown out a snippet and expected the community to work out what it is that you want to happen...

I will keep note of that.. The reason partly maybe that it was Midnight and I was sleepy when I posted my questions recently, sorry! :sweating:

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

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