TheDcoder

Prevent combo from updating before user selects a item in it

12 posts in this topic

#1 ·  Posted (edited)

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

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites




AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

@Melba23 Not what I was expecting, I need all the elements to be in the combo :(


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
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

 

1 person likes this

Share this post


Link to post
Share on other sites

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

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
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:


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

@LarsJ I did read the Remarks but ignored the example :sweating:


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

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