Jump to content
Sign in to follow this  
doestergaard

Need help with populating .wim files from a folder into a combo box

Recommended Posts

doestergaard

I can't seem to figure out the logic behind injecting data to a combo box. So far I have tried almost any suggestion in this forum, but with no results.

I know its because Im not doing it right, so any help is very much appreciated.

 

Here is my code:

$selectOperatingSystems = GUICtrlCreateCombo ( "", 106, 180, 412, 20, $CBS_DROPDONWLIST )
_GUICtrlComboBox_AddDir ( $selectOperatingSystems, "Z:\images\*.wim" )

Thanks in advance!

Share this post


Link to post
Share on other sites
orbs

you limit the height of the ComboBox to 20 px. change to something un-limiting, like 1000 or so. it will downsize to fit.

P.S. welcome to AutoIt and to the forum!

Edited by orbs

Share this post


Link to post
Share on other sites
doestergaard

The height, really? :D [solved]

Share this post


Link to post
Share on other sites
doestergaard

I may have another question. Now that the combo box has been populated with the files from folder, I would like to add a string to each item in the list

Example:

"1. "

"2. "

"3. "

Is that possible?

Thanks again!

Edited by doestergaard

Share this post


Link to post
Share on other sites
orbs

Is that possible?

 

yes.

does it worth it? i don't believe so. remember that when the user selects a wim file from your list, you will have to undo all strings manipulation you want to do. also your wim files may no longer be sorted alphabetically in the list once you prefix them with numbers.

anyway...

the function you have chosen to use, _GUICtrlComboBox_AddDir , is a UDF - that's User Defined Function. this means that a user wrote it for his/her needs, and later someone saw fit to include it in the AutoIt package. if you want it according to your needs, you will need to modify the function.

in your case, it does not seem too complicated: the function is included in the, well... #include file. find it, copy it to your script, rename it slightly to avoid conflict in function name, then modify the line:

_GUICtrlComboBox_InsertString($hWnd, $sText)

into something like this:

_GUICtrlComboBox_InsertString($hWnd, $i & ". " & $sText)

disclaimer: i did not test this, but that's what i'd do (if forced by torture).

Share this post


Link to post
Share on other sites
doestergaard

@orbs

This code does it in my vbscript file:

FolderPath = "Z:\images"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(FolderPath)
Set colWimFile = objFolder.Files

For Each objWimFile In colWimFile

   Set objOption = Document.CreateElement("OPTION")
   objOption.Value = objFSO.GetBaseName(objWimFile)
   X = X + 1
   objOption.Text = X & "." & " " & objFSO.GetBaseName(objWimFile)
   selectWimFile.Add(objOption)

Next

Any chance that i could use the vbscript to populate it into my combo box?

Thanks

Share this post


Link to post
Share on other sites
orbs

AutoIt is shipped with a mighty arsenal of functions. using external scripts is needless and prone to issues.

check this out:

_FileListToArray()

this will create an array of files in memory. with this array you can do many thing in the same script: for example, 1) fill a ComboBox with your desired format, and 2) process the response.

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  

×