Sign in to follow this  
Followers 0
nevodj

Using key value and display value in Combobox

7 posts in this topic

Hello,

In my GUI I have a combobox that is populated from an SQL query, like select id, name from persons.

In the combobox I want to display the name, but when the person's name is selected from the combobox, I want to retrieve the id relevant to the selected person, so I can use it later in the script.

GUICtrlRead will return the person name, but that will not work as it may not be unique.

How can I read the ID of the selected person?

It's hard to explain, apologies if this is not clear.

Share this post


Link to post
Share on other sites



nevodj,

If the names may not be unique in the combo, how do you know you have selected the correct one? Why not display both name and ID in the combo? :huh:

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

I knew someone would ask that.... ID is a database primary key so means nothing to the user. To deal with duplicates in the list, I may display name and city or something like that.

 

Share this post


Link to post
Share on other sites

nevodj,

How is the data returned from the database? I imagine it is an array from which you extract elements to populate the combo. If so then just search the array for matches to the name (and whatever else you decide to add to make them unique) and read off the associated ID. :)

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

Hello,

I am using the _Sql_GetTableAsString function to get the data as a string, then stringreplace to replace the carriage returns in the string with pipes, then using guictrlsetdata to push that into the combobox.

I am not sure how I'd load multiple fields. Any help is appreciated.

Share this post


Link to post
Share on other sites

nevodj,

I am not a database expert, and what little I do know is based on SQLite and its associated UDF whereas I assume you are using this SQL UDF. It sounds to me from your post that you are pulling the names as a single query. With that UDF can you not get both the name and the identifier you will have to use (city?) at the same time? Then you will be able to add both to the combo and re-query the database to extract the ID once a selection is made. :huh:

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 will look into this.

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