KatoXY

Drop-down list

24 posts in this topic

#1 ·  Posted (edited)

Hello,

I want to write a script and I need use GUI command but I don’t know which 

I need in my script a list with all records from array or excel book. This list has to look like drop-down list with fonts in MS Word or their size.

Could you show me?

I looked again on AutoIt Help. There are many function with drop down list.

I have to precise describe what I need and then I ask again.

post-60731-0-64819900-1301550233_thumb.j

Edited by KatoXY

Share this post


Link to post
Share on other sites



KatoXY,

The control is know as a Combo and you can produce one by using GUICtrlCreateCombo. :)

If you want to fill it from an array, I would recommend doing something like this:

#include <GUIConstantsEx.au3>

; Here is the array
Global $aArray[5] = ["A", "B", "C", "D", "E"]

; And here we get the elements into a list
$sList = ""
For $i = 0 To UBound($aArray) - 1
    $sList &= "|" & $aArray[$i]
Next

; Create a GUI
#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

; Create the combo
$hCombo = GUICtrlCreateCombo("", 10, 10, 200, 20)
; And fill it
GUICtrlSetData($hCombo, $sList)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

All clear? Please ask if not. :)

M23

1 person likes this

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

Yes it's clear and great.

I have 2d array and in ComboBox I want only 1st column, so I improve your script:

; Here is the array
Global $aArray[5][2] = [["Andy", "Football"], ["Jon", "Swimming"], ["Jeremy", "Tennis"], ["Carol", "Basketball"], ["Vicky", "Hockey"]]

; And here we get the elements into a list
$sList = ""
For $i = 0 To UBound($aArray,1) -1
    $sList &= "|" & $aArray[$i][0]
Next

; Create a GUI
#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

; Create the combo
$hCombo = GUICtrlCreateCombo("", 10, 10, 200, 20)
; And fill it
GUICtrlSetData($hCombo, $sList)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
[/code]

Then I need to see label, list or small window, next to ComboBox, with data from 2nd column of my array

and create dependency: when I chose in Combo i.e: Jeremy then I see Tennis in label, window.

How to do it?

Share this post


Link to post
Share on other sites

KatoXY,

Perhaps like this? :)

#include <GUIConstantsEx.au3>
#include <Array.au3>

; Here is the array
Global $aArray[5][2] = [["Andy", "Football"], ["Jon", "Swimming"], ["Jeremy", "Tennis"], ["Carol", "Basketball"], ["Vicky", "Hockey"]]

; And here we get the elements into a list
$sList = ""
For $i = 0 To UBound($aArray,1) -1
    $sList &= "|" & $aArray[$i][0]
Next

; Create a GUI
#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

; Create the combo
$hCombo = GUICtrlCreateCombo("", 10, 10, 200, 20)
; And fill it
GUICtrlSetData($hCombo, $sList)

; Create label
$hLabel = GUICtrlCreateLabel("", 220, 15, 200, 20)

GUISetState()
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hCombo
            $sName = GUICtrlRead($hCombo)
            $iIndex = _ArraySearch($aArray, $sName)
            If Not @error Then
                GUICtrlSetData($hLabel, $aArray[$iIndex][1])
            EndIf
    EndSwitch
WEnd

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

Yeah, It's working very good. You are :)

It helps me write my script. :)

I will contact you If I have some trouble

Thanks

:P

Share this post


Link to post
Share on other sites

atoXY,

I will contact you If I have some trouble

Just post in the forum - if I am not around someone else will help. :)

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

Thank you for this. I just posted on another thread about much the same thing. There is documentation on Combo boxes and documentation on Arrays, but I struggled (really!) to find an example of getting an array into a Combo box - and this one is just so smart - with lots of extra goodies, and the example is clear and simple

Could this perhaps, please, be included in the standard documentation? Perhaps as an 'Advanced Example' in the GUICtrlCreateCombo help item?

Thank you for your efforts. 


Skysnake

Why is the snake in the sky?

Share this post


Link to post
Share on other sites

Skysnake,

All you need do to get an array into a combo is to convert the array to a string - and the _ArrayToString function will do that for you if you do not want write your own. ;)

But thanks for the compliments. :)

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

#9 ·  Posted (edited)

On 3/31/2011 at 3:41 PM, Melba23 said:

KatoXY,

 

Perhaps like this? :)

 

#include <GUIConstantsEx.au3>
#include <Array.au3>

; Here is the array
Global $aArray[5][2] = [["Andy", "Football"], ["Jon", "Swimming"], ["Jeremy", "Tennis"], ["Carol", "Basketball"], ["Vicky", "Hockey"]]

; And here we get the elements into a list
$sList = ""
For $i = 0 To UBound($aArray,1) -1
    $sList &= "|" & $aArray[$i][0]
Next

; Create a GUI
#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

; Create the combo
$hCombo = GUICtrlCreateCombo("", 10, 10, 200, 20)
; And fill it
GUICtrlSetData($hCombo, $sList)

; Create label
$hLabel = GUICtrlCreateLabel("", 220, 15, 200, 20)

GUISetState()
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hCombo
            $sName = GUICtrlRead($hCombo)
            $iIndex = _ArraySearch($aArray, $sName)
            If Not @error Then
                GUICtrlSetData($hLabel, $aArray[$iIndex][1])
            EndIf
    EndSwitch
WEnd

M23

How If need Global $aArray = "Combo.ini"

[Data]
[Andy Football]
[Jon Swimming] 
[Jeremy Tennis]
[Carol Basketball]
[Vicky Hockey]

 

Edited by heroeda

Share this post


Link to post
Share on other sites

#10 ·  Posted

heroeda,

If you correctly format your ini file than IniReadSection will give you a 2D array to use:

[Data]
Andy=Football
Jon=Swimming 
Jeremy=Tennis
Carol=Basketball
Vicky=Hockey
#include <Array.au3>

$aData = IniReadSection("Combo.ini", "Data")

_ArrayDisplay($aData, "", Default, 8)

M23

P.S. When you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - I know what I wrote and it just pads the thread unnecessarily.

 


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

#11 ·  Posted (edited)

M23

why combo list not show 

Global $aArray[5][2] <------ this code delete or not.

Edited by heroeda

Share this post


Link to post
Share on other sites

#12 ·  Posted

Solved and thanks Melba23

I change code:

$aData = IniReadSection("Combo.ini","Data")
$aArray = $aData

; List element
$sList = ""

For $i = 0 To UBound($aArray,1) -1
    $sList &= "|" & $aArray[$i][0]

 

 

Share this post


Link to post
Share on other sites

#13 ·  Posted

Just a quick comment/critique.  Creating another Array variable and copying the $aData array to it is unnecessary/erroneous, unless you really need to retain the original array; but since you are just reading from it and not updating it I don't think that adds any value here.  I would however suggest some error checking to ensure that the variable is in fact an array.  Something to chew on:

$aData = IniReadSection("Combo.ini","Data")
If @error Or Not IsArray($aData) Then
    ;Error condition logic - Notify user, exit function, what-have-you
EndIf

; List element
$sList = ""

For $i = 0 To UBound($aData,1) -1
    $sList &= "|" & $aData[$i][0]

 

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

can someone help me with this,  I have 1 drop list base on selection radio1 or radio2   it will display a different content to select on the list

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 255, 253, 192, 124)
$Radio1 = GUICtrlCreateRadio("Radio1", 40, 48, 65, 17)  ; IF RADIO1 SELECTED LIST0 IS SELECTED
$Radio2 = GUICtrlCreateRadio("Radio2", 128, 48, 65, 17)  ;IF RADIO2 SELECTED LIST1 IS SELECTED
$Group1 = GUICtrlCreateGroup("POS", 24, 24, 177, 49)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $slist[1]                      ;index to keep list 0,1
Global $aArray0[5] = [1,2,3,4,5]    ;VALUE LIST0
Global $aArray1[5] = [6,7,8,9,10]   ;VALUE LIST1

; fill both arrary0, array1 with the content for list 0 and list 1 respectively
$sList[0] = ""
;~$slist[1] = ""

For $i = 0 To UBound($aArray0) - 1
    $sList[0] &= "|" & $aArray0[$i]

;~For $j = 0 To UBound($aArray1) - 1
;~    $sList[1] &= "|" & $aArray1[$j]
;~Next
Next

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

 

Edited by antonioj84
ok

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

What do you need help with?  I didn't see a clear question above...so I'll guess.

  • Displaying the list?
    • How do you want it displayed? (ArrayDisplay, Listview, ConsoleWrite, etc.)
  • Assigning the desired list to $sList?
  • Other?
Edited by spudw2k

Share this post


Link to post
Share on other sites

#16 ·  Posted

Hi spudw2k,

If radio1 or radio2 is selected the dropdown list content for selecting will be different.

Radio0 will list on the dropdown 1,2,3,4,5

Radio1 will list on the dropdown

5,6,7,8,910

Note bien, there is only on dropdown list only the content for selection will be different base on the checked option radio0 or radio1

Share this post


Link to post
Share on other sites

#17 ·  Posted

Ok, should be easy enough.  Do you have more code with the dropdown list control already in place?  Is it a combobox?

Also, just a thought....will your arrays be changing during runtime, or will they always be defined, hardcoded in the script?  You might as well just have them be strings to begin with.  That way you don't have to do any additional processing/formatting before applying the data to the dropdown.

Share this post


Link to post
Share on other sites

#18 ·  Posted

Kool, the array values are hard-coded and won't change, sure i can have them as a string.

I need assistance in filling the 2  $list[1] from the $array0 and $array1

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

Well, if you use strings instead, you don't need to bother with populating the $slist[1].  

Global $slist[1]                      ;index to keep list 0,1
Global $aArray0[5] = [1,2,3,4,5]    ;VALUE LIST0
Global $aArray1[5] = [6,7,8,9,10]   ;VALUE LIST1

;would become
Global $sList1 = "|1|2|3|4|5"
Global $sList2 = "|6|7|8|9|10"

Also, an array with only 1 index ($sList[1]) doesn't add any value that I can see that you can't accomplish with a string, or am I missing something?   If you really want to do it using arrays, I won't stop you.  Just trying to make things simpler for ya.  You were on your way there with your for loop.  
 

Edited by spudw2k
added preceding GUISeparatorChar to list strings to ease updating combo
1 person likes this

Share this post


Link to post
Share on other sites

#20 ·  Posted

$sList1=""
If GUICtrlRead($Box1) = $GUI_CHECKED Then
   $sList1 = "|1|2|3|4|5"
EndIf
$sList1=""
If GUICtrlRead($Box2) = $GUI_CHECKED Then
  $sList1 = "|6|7|8|9|10"
EndIf

this solution will work for sure, however I was shooting for my solution

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