Jump to content

[SOLVED] Combo-Box Problem


Floppy
 Share

Recommended Posts

Hello,

How can I get the selected item in a combo-box?

I tried with _GUICtrlComboBox_GetCurSel, but it gets the hovered item index.

I want to get the item index, only when the user click on it.

I tried with GuiCtrlRead, but it gets the text of the item.

I want to get the item index and not the text.

Thanks. :)

Edited by FSoft
Link to comment
Share on other sites

  • Moderators

FSoft,

I usually get the selected text with GUICtrlRead and then use that text in _GUICtrlComboBox_FindStringExact to find the corresponding index.

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

An alternative.o normal methods... :)

Make sure you look the _GUICtrlComboBox_* functions too.

Global Const $CBS_DROPDOWNLIST = 0x0003
Global $aComboText[5]
$aComboText[0] = 4
$aComboText[1] = "Bust"
$aComboText[2] = "Cost"
$aComboText[3] = "Lost"
$aComboText[4] = "Lose"

$hGUI = GUICreate("GUI Title", 200, 100)
$hCombo = GUICtrlCreateCombo("Lust", 10, 10, 180, 33, $CBS_DROPDOWNLIST)

For $i = 1 To $aComboText[0]
    GUICtrlSetData($hCombo, $aComboText[$i])
Next
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case - 3
            Exit
        Case $hCombo
            $read = GUICtrlRead($hCombo)
            For $i = 1 To $aComboText[0]
                If $read = $aComboText[$i] Then 
                    $i += 1
                    ExitLoop
                EndIf
            Next
            MsgBox(0, "", "Index = " & $i)
    EndSwitch
WEnd

Cheers,

Brett

Link to comment
Share on other sites

  • Moderators

FSoft,

To satisfy my curiosity, could you please explain why the fact that your program is "multilanguage" prevents you getting the selected text from a combobox with GUICtrlRead? To my simple mind, the actual language of the text is immateriel - the content of the combobox input is merely a string of bytes in memory somewhere.

Thanks in advance if you can find the time to elaborate.

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

The program I'm working on will be multilanguage: Italian, English, Spanish, ecc.

Then in English in the combo there are the following strings: Hello|Bye|Goodbye|Good morning. (It's only an example :))

In Italian: Ciao|Ciao|Arrivederci|Buongiorno.

In Spanish: Hola|Adiós|Adiós|Buenos días

If I get the text with GuiCtrlRead, I should write the If loops for each language!

I hope you understand me now!

---------------------------------------------------------

@ BrettF: Thank you...the script works greatly!

Link to comment
Share on other sites

  • Moderators

FSoft,

But that is exactly why you need _GUICtrlComboBox_FindStringExact - it does all the searching for you!

Try this:

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

GUICreate("Test", 200, 200)

$hCombo = GUICtrlCreateCombo("", 10, 10, 180, 20, $CBS_DROPDOWNLIST)

GUICtrlSetData(-1, "Hello|Bye|Goodbye|Good morning", "")
;GUICtrlSetData(-1, "Ciao|Ciao2|Arrivederci|Buongiorno", "")
;GUICtrlSetData(-1, "Hola|Adiós|Adiós2|Buenos días", "")

$hButton = GUICtrlCreateButton("Select", 60, 160, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            $sSelection = GUICtrlRead($hCombo)
            Local $iIndex = _GUICtrlComboBox_FindStringExact($hCombo, $sSelection)
            MsgBox(0,"Index", $iIndex)
    EndSwitch

WEnd

You do nothing - the function does the searching for you. You can put any language you like in the combo (try it with the other lines that are commented out above) and you have no loops to write. That is why I asked you for a few more details. It will find the first match - that it why I have amended "Ciao2" and "Adios2" to distinguish them.

I hope you understand ME now!

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

FSoft,

But that is exactly why you need _GUICtrlComboBox_FindStringExact - it does all the searching for you!

Try this:

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

GUICreate("Test", 200, 200)

$hCombo = GUICtrlCreateCombo("", 10, 10, 180, 20, $CBS_DROPDOWNLIST)

GUICtrlSetData(-1, "Hello|Bye|Goodbye|Good morning", "")
;GUICtrlSetData(-1, "Ciao|Ciao2|Arrivederci|Buongiorno", "")
;GUICtrlSetData(-1, "Hola|Adiós|Adiós2|Buenos días", "")

$hButton = GUICtrlCreateButton("Select", 60, 160, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            $sSelection = GUICtrlRead($hCombo)
            Local $iIndex = _GUICtrlComboBox_FindStringExact($hCombo, $sSelection)
            MsgBox(0,"Index", $iIndex)
    EndSwitch

WEnd

You do nothing - the function does the searching for you. You can put any language you like in the combo (try it with the other lines that are commented out above) and you have no loops to write. That is why I asked you for a few more details. It will find the first match - that it why I have amended "Ciao2" and "Adios2" to distinguish them.

I hope you understand ME now!

M23

Thanks for help!
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...