Jump to content

GUICtrlCreateCombo to and mouse scroll wheel problem


KEHT
 Share

Go to solution Solved by Melba23,

Recommended Posts

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

Link to comment
Share on other sites

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.
Link to comment
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.  :(

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

  • Moderators
  • Solution

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

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

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