Sign in to follow this  
Followers 0
Myicq

Dropdown or list view with key and value

3 posts in this topic

This question must have been asked before, but I just can't seem to find it. So forgive me if asking in duplicate...

I have a small app where users must select a function to execute against their data.

The function consists of 3 parts: pre, main, post. All setup is from an SQLite database.

My question is: how can I present the choice to the user, and at the same time be sure to receive a unique ID on the function ? Essentially I would like to have a dropdown with two columns: ID and value, where ID is returned to me, while value is presented to user.

I COULD of course match against "description", but it MAY happen that descriptions are not unique.

Example:

1;function A
2;function B
3;newfunc
4;newfunc
5;last function here

Is there any way to do this ? I have been considering listview controls, but would prefer dropdown.

However a dropdown consisting of [id] & ":" & [desc] to give [1:function A] is not quite desired.

Hope I have been clear enough.


I am just a hobby programmer, and nothing great to publish right now.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

If these functions may not have unique descriptions, I have to logically assume that they are dynamically added by the user.

if that is correct then I would dynamically add an ID when that happens.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

how about something like this? A 2D array that holds the value and the function associated with it. Notice that value 1 and 2 execute the function _a() and value 3 execute the function _b():

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

$GUI = GUICreate("Test", 400, 600)
$COMBO = GUICtrlCreateCombo("", 20, 40, 360)
GUICtrlSetOnEvent($COMBO, "_Events")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Events")
GUISetState()

;Declare the array that hold the controlID and the function to execute:
Global $aValues[3][2] = [["value 1", "_a()"], ["Value 2", "_a()"], ["Value 3", "_b()"]]

;Fill the combo with the values:
Global $sComboValues
For $i = 0 To UBound($aValues) -1
    $sComboValues &= $aValues[$i][0] & "|"
Next
GUICtrlSetData($COMBO, $sComboValues, $aValues[0][0])


While 1
    Sleep(250)
WEnd

Func _Events()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            Exit

        Case $COMBO
            ;read the value in the combo:
            Local $ValueSelected = GUICtrlRead($COMBO)

            ;Search the value in the array:
            For $i = 0 To UBound($aValues) -1
                If $aValues[$i][0] = $ValueSelected Then
                    ;Found then execute the function
                    Return Execute($aValues[$i][1])
                EndIf
            Next
    EndSwitch
EndFunc

Func _a()
    MsgBox(0, "Func A", "Func A executed")
EndFunc

Func _b()
    MsgBox(0, "Func B", "Func B executed")
EndFunc

That would also work with a listview, if you can prepare your array before and then fill the listview with the values from the array.

Edited by jmon

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