Floppy Posted February 22, 2009 Share Posted February 22, 2009 (edited) 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 February 23, 2009 by FSoft Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 22, 2009 Moderators Share Posted February 22, 2009 FSoft,I usually get the selected text with GUICtrlRead and then use that text in _GUICtrlComboBox_FindStringExact to find the corresponding index.M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Floppy Posted February 22, 2009 Author Share Posted February 22, 2009 Yes, but I cannot get text because I'm working on a program multilanguage!Is there another solution? Link to comment Share on other sites More sharing options...
BrettF Posted February 22, 2009 Share Posted February 22, 2009 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 Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 22, 2009 Moderators Share Posted February 22, 2009 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Floppy Posted February 23, 2009 Author Share Posted February 23, 2009 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íasIf 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 More sharing options...
Moderators Melba23 Posted February 23, 2009 Moderators Share Posted February 23, 2009 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 WEndYou 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Floppy Posted February 23, 2009 Author Share Posted February 23, 2009 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now