Sign in to follow this  
Followers 0
KEHT

GUICtrlCreateCombo to and mouse scroll wheel problem

6 posts in this topic

Hello again guys!

I ran into another problem I am trying to solve.  I have a ComboBox control with a long list of names.  When one of them is selected its value is added to a List control below.  The problem I am having is that when a name is selected in a combobox and mouse wheel is scrolled all the names that are scrolled through get added to a List control below.  My users indicated this as undesirable behavior.  I am not sure whether it is a default or not, but I'm trying to get rid of it.  I tried shifting focus after the name is selected, but it did not work too well.  I am now trying to figure out a way to only allow selection when ComboBox is extended or only allow selection specifically by clicking left mouse button.  Can anybody provide any suggestions??? 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You can add a button, and only add the selected 'combo' value when the 'add' button is clicked.

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

You can add a button, and only add the selected 'combo' value when the 'add' button is clicked.

Unfortunately, that's not an option in my case as I am limited by the requirements to have the same number and type of elements as the previous version of software I am recreating.  :(

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Then you have to key off the click, and not the change in text.  Maybe loss of focus will do you.

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

KEHT,

I would do it like this:

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

; Flag to show if combo has dropped
Global $bSelected = False

$hGUI = GUICreate("Test", 500, 500)

$cCombo = GUICtrlCreateCombo("", 10, 10, 200, 20)
GUICtrlSetData($cCombo, "1|2|3|4|5|6|7|8|9")

$cList = GUICtrlCreateList("", 10, 100, 200, 200, BitOR($WS_BORDER, $WS_VSCROLL))

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cCombo
            ; If combo has dropped
            If $bSelected Then
                ; Clear flag
                $bSelected = False
                ; Add data
                GUICtrlSetData($cList, GUICtrlRead($cCombo))
            EndIf
    EndSwitch

    ; look for combo dropping
    If _GUICtrlComboBox_GetDroppedState($cCombo) Then
        ; Set flag
        $bSelected = True
    EndIf

WEnd
You could probably look for a message that the combo has been dropped rather then polling in the loop - but I leave that to you to code. ;)

Please ask if anything is unclear. :)

M23

Edit:

Actually the message code is really easy, so here it is: ;)

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

; Flag to show if combo has dropped
Global $bSelected = False

$hGUI = GUICreate("Test", 500, 500)

$cCombo = GUICtrlCreateCombo("", 10, 10, 200, 20)
GUICtrlSetData($cCombo, "1|2|3|4|5|6|7|8|9")

$cList = GUICtrlCreateList("", 10, 100, 200, 200, BitOR($WS_BORDER, $WS_VSCROLL))

GUISetState()

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cCombo
            ; If combo has dropped
            If $bSelected Then
                ; Clear flag
                $bSelected = False
                ; Add data
                GUICtrlSetData($cList, GUICtrlRead($cCombo))
            EndIf
    EndSwitch

WEnd

Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)

    If _WinAPI_HiWord($wParam) = $CBN_DROPDOWN Then
        ; Set flag
        $bSelected = True
    EndIf

EndFunc
Edited by Melba23
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

Thanks, @Melba23 !!! That did the trick perfectly!!!

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