Sign in to follow this  
Followers 0
Stoex

ComboBox to ListView selection

12 posts in this topic

I have a populated ComboBox from which a selection is made and added to a ListView
I want to be able to drop down the ComboBox and use the scroll bar OR use the arrow keys to move up or down before making a selection. Selection is currently made by mouse click upon selected item in ComboBox.
What I got was the arrow keys (up/down) also added item from ComboBox to ListView - NOT desired.
I don't want to make a selection and then use a button to make the transition from Combox to ListView.
Any ideas on the below code for help would be appreciated and part of my learning curve to this coding.
Thanks.
GUISetOnEvent($GUI_EVENT_PRIMARYUP, "Clicker")


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

        Case $hcombo  ;adds combo selection to listview
                 Local $sComboRead = GUICtrlRead($hcombo)
        
            if Not _IsPressed ("26") Then ;up arrow key
                Clicker()
            ElseIf not _IsPressed("28") Then ;down arrow key
                Clicker()
            EndIf


    EndSwitch
WEnd


Func Clicker()
    
    GUICtrlSetData ( $List1,  $sComboRead  )
    EndFunc

 

Share this post


Link to post
Share on other sites



Do not use the message from the combobox to populate the list, create a separate button that when clicked reads the combo and does what you want. Every action done on the combobox, even just clicking the edit box, can trigger your script.


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

Stoex,

Perhaps something like this will suit: :)

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

Global $fComboSelected = False

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

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

$cLV = GUICtrlCreateListView("Items      ", 250, 10, 200, 200)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cCombo
            ; Set flag to show new selection made
            $fComboSelected = True
            ConsoleWrite("Combo changed" & @CRLF) ; Just for dem0
    EndSwitch

    If $fComboSelected Then
        ; Check if dropdown closed
        If _GUICtrlComboBox_GetDroppedState($cCombo) = False Then
            ; Create LV item
            GUICtrlCreateListViewItem(GUICtrlRead($cCombo), $cLV)
            ; Clear flag
            $fComboSelected = False
        EndIf
    EndIf

WEnd
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

M23

You hit the ball out of the ball park.  That is exactly what I was attempting to do.

It seemed logical to me that it could be done, but alas as I am so very new to this coding, I guess I had a caveman approach to it.

So now it is...wax on, wax off grasshopper!

Thanks for the reply and thanks for the speed of your reply as well.

Share this post


Link to post
Share on other sites

M23 -

Just noticed something when executing your code.

When first starting the code (without dropping down the combo), if I arrow down with arrow key, it moves through the items and at the same time adds them to ListView.  Is that normal or coded as such?  If drop down the Combo and arrow through items are appropriately added.

Should I add a line for hitting the "enter key"?  Thanks again for taking time for my stuff!

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Stoex,

We need to add another check:

; Set flag to show new selection made
If _GUICtrlComboBox_GetDroppedState($cCombo) = True Then
    $fComboSelected = True
    ConsoleWrite("Combo changed" & @CRLF) ; Just for dem0
EndIf
Now we only trigger the insertion if the combo has been opened. How about that? :)

M23

Edited by Melba23
Wrong username

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

#7 ·  Posted (edited)

Hey M23!

Ok, I inserted your last "flag" you posted - in attached code. Here is what happens:

At start up when launched - everything is good and in place.

With the cursor focused in the box, if the arrow keys are hit, items will show in the box(thats good/ok) and get added to the Listview(thats not desired or good/ok). Showing up in the box is fine but not the adding.

When the combo is dropped and item selected it gets added which is desired and works.

Any thoughts on what I should look at next. It is soooo close.

Thanks.

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

Global $fComboSelected = False

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

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

$cLV = GUICtrlCreateListView("Items      ", 250, 10, 200, 200)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cCombo
            ; Set flag to show new selection made
            $fComboSelected = True
            ConsoleWrite("Combo changed" & @CRLF) ; Just for dem0
    EndSwitch

    If $fComboSelected Then
        ; Check if dropdown closed
        If _GUICtrlComboBox_GetDroppedState($cCombo) = False Then
            ; Create LV item
            GUICtrlCreateListViewItem(GUICtrlRead($cCombo), $cLV)
            ; Clear flag
            $fComboSelected = False
        EndIf
; Set flag to show new selection made
        If _GUICtrlComboBox_GetDroppedState($cCombo) = True Then
        $fComboSelected = True
        ConsoleWrite("Combo changed" & @CRLF) ; Just for dem0
            EndIf




    EndIf

WEnd
Edited by Stoex

Share this post


Link to post
Share on other sites

Stoex,

If you put the code snippet I posted in the correct place, it should work: ;)

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

Global $fComboSelected = False

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

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

$cLV = GUICtrlCreateListView("Items      ", 250, 10, 200, 200)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cCombo
            ; Set flag to show new selection made <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            If _GUICtrlComboBox_GetDroppedState($cCombo) = True Then
                $fComboSelected = True
                ConsoleWrite("Combo changed" & @CRLF) ; Just for demo
            EndIf ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    EndSwitch

    If $fComboSelected Then
        ; Check if dropdown closed
        If _GUICtrlComboBox_GetDroppedState($cCombo) = False Then
            ; Create LV item
            GUICtrlCreateListViewItem(GUICtrlRead($cCombo), $cLV)
            ; Clear flag
            $fComboSelected = False
        EndIf
    EndIf

WEnd
How is that? ;)

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
Hey M23!
Somewhere between your first post and the last post is what I was trying to achieve. Being new at this I may be a light weight in communicating what is being attempted, so I apologize.
Once the app is started I'm would like to be able to add items from the ComboBox to the ListView by any of the following:
 
1.drop down the box
       a. choose item
            1. by arrowing down/enter key or click
            2. mouse cursor pointing/clicking it
       b. above action copies item to ListView
 
2. not drop down the box
       a. choose item
          1. by arrowing through choices/enter key
       b. above action copies item to ListView

Share this post


Link to post
Share on other sites

Stoex,

My final attempt using a very different approach: :)

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

Global $tInfo, $fComboActive = False

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

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

_GUICtrlComboBox_GetComboBoxInfo($cCombo, $tInfo)
$hEdit = DllStructGetData($tInfo, "hEdit")

$cLV = GUICtrlCreateListView("Items      ", 250, 10, 200, 200)

$cEnterPressed = GUICtrlCreateDummy()

GUISetState()

Global $aAccelKeys[1][2] = [["{ENTER}", $cEnterPressed]]
GUISetAccelerators($aAccelKeys)


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYUP
            If $fComboActive Then
                GUICtrlCreateListViewItem(GUICtrlRead($cCombo), $cLV)
                $fComboActive = False
                _GUICtrlComboBox_ShowDropDown($cCombo, False)
            EndIf
        Case $cEnterPressed
            If _WinAPI_GetFocus() = $hEdit Then
                GUICtrlCreateListViewItem(GUICtrlRead($cCombo), $cLV)
                _GUICtrlComboBox_ShowDropDown($cCombo, False)
            EndIf
    EndSwitch

    If _GUICtrlComboBox_GetDroppedState($cCombo) = True Then
        $fComboActive = True
    EndIf
WEnd
If that does not fit the bill, I am going to suggest using a separate "Select" button. ;)

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

Thanks M23!

I'll give it a look.

In the mean time here is what I came up with. Take a look and please critique it.  I only got this far, with your help.

I think it fits the requirements. I did notice that in my code for the "enter" key process that after selecting the item it is highlighted in the combobox and for the "enter" key to process the add, I have to "arrow" over (or unhighlight) the item. That is next on my list.

Again - it is only because of your example that my growth in this coding has moved forward, albeit a snail's pace compared to the expertise I find at this forum.

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

Global $fComboSelected = False

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

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

$cLV = GUICtrlCreateListView("Items      ", 250, 10, 200, 200)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cCombo
            ; Set flag to show new selection made
            $fComboSelected = True
            ConsoleWrite("Combo changed" & @CRLF) ; Just for dem0
    EndSwitch

    If $fComboSelected Then
        ; Check if dropdown closed
        If _GUICtrlComboBox_GetDroppedState($cCombo) = False Then
            ; Create LV item
            if _IsPressed("0D") Then
            GUICtrlCreateListViewItem(GUICtrlRead($cCombo), $cLV)
            ; Clear flag
            $fComboSelected = False
        EndIf
        if _IsPressed("01") Then
            GUICtrlCreateListViewItem(GUICtrlRead($cCombo), $cLV)
            ; Clear flag
            $fComboSelected = False
        EndIf


        EndIf
    EndIf

WEnd

Share this post


Link to post
Share on other sites

Stoex,

I think it fits the requirements

Great - then I consider the problem solved. :)

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

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