Sign in to follow this  
Followers 0
mmeado

ComboBox Questions

5 posts in this topic

Hello,

I have a couple questions related to creating comboboxes.

I have been using Autoit for a few years now, and cannot find a solution to what I'm trying to accomplish.

I have created a Combo box which is populated from a SQL database.

First, I would like the ComboBox to have a different value then what is displayed, similar to HTML. For example, I want the option that the users selects to have a different value then the displayed text; Say in the ComboBox one option is "HP Compaq 6000 Pro SFF", but I want the value to be "6000PSFF". You can do this in an HTA with HTML, can this be done in AutoIt?

Second, I would like the width of the ComboBox to be defined by the largest option in the ComboBox, so there is really no static width, because I don't nessessarily know the length of the options to determine the width.

If anybody has any insight I would apprecitate it.

Thanks,

Mike

Share this post


Link to post
Share on other sites



To get the combobox to display the information in a reformatted fashion, you'd need to reformat it before putting it into the contents of the combo, there's no built-in function to do that for you. To make the combo box as wide as the widest string in that box, you'd need to determine which string is the longest string first, then size/resize your combobox accordingly. I would suggest looking for the StringSize UDF created by Melba23 to help with finding out the size of the combo box you'd need for the size of the string you have.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

BrewManNH,

Thanks for the info. Setting the width to the length of the longest string should be easy enough, just didn't know if there was a style which controlled that. With HTML that is the standard behavior of a select box.

As far as "reformat it before putting it into the contents of the combo", I'm not sure what you mean.

I'm looking for something similar to the way a "Select" tag works in HTML. The "option" element of a select tag has different properties, the "text" property which displays the text a users sees, and a "value" property which contains a hidden value to the user which is used for the programming.

Is there a way to do this with a ComboBox? If not, do you have an example of how I could store this extra value I need for the selected option? Or explain what you mean by reformat before adding the contents.

Thanks again,

Mike

Share this post


Link to post
Share on other sites

You can use two dimensional array prepared for populating/reading ComboBox.

In first array column will be hidden value for each Combo line

and in second array column will be value for display

After you select desired row of Combo then you use index of this row to get hidden value from your array.

Share this post


Link to post
Share on other sites

Zedna,

Thanks for the response. I've never worked with a 2D array before in AutoIt. Does anyone have an example of how to build a dynamic 2D array?

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