Sign in to follow this  
Followers 0
Damein

Getting the number of the selected item in a ComboBox?

3 posts in this topic

So, I have a ComboBox and I have 3 items in it.

I want to be able to get the number I have selected, not the name.

I know I can get the selection via:

ControlGetText("Name", "", $ComboBox)

But in order for me to accomplish something I need to get the number.

IE:

ComboBox = Red|Blue|Green

And instead of getting: Red I want to get 1 and etc.

Thanks ;)


MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Share this post


Link to post
Share on other sites



If you still have the original array data available you could try something like this. (Native AutoIt, untested after rewriting it a bit.)

Func Get_ComboSelectedId($hCombo, $asDataLines)
    
    Local $sSelectedText = GUICtrlRead($hCombo)
    Local $iEntryId = -1 ;; zero based.
    
    For $i = 0 To UBound($asDataLines, 1) - 1
        If Not ($asDataLines[$i] == $sSelectedText) Then ContinueLoop ;; case sensitve.
        
        $iEntryId = $i
        ExitLoop
    Next
    
    If $iEntryId < 0 Then SetError(1)
    Return $iEntryId
EndFunc

Or take a look at "_GUICtrlComboBox_GetCurSel" -> GuiComboBox UDF.

Note: In general is best to only use GuiComboBox UDF functions on Combobox's that are also created with GuiComboBox UDF.


"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Or take a look at "_GUICtrlComboBox_GetCurSel" -> GuiComboBox UDF.

Or
ControlCommand("Window Handle or Title", "Text If Any", "ControlID/ClassNameNN/Handle", "GetCurrentSelection", "")
(If it's a standard window of course)

Edit:

I didn't notice you wanted the actual drop down index number. It might be better to use the _GUI* UDFs indeed.

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

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