Jump to content

Recommended Posts

Joep86

Hi, 

I just started recently with AutoIT and I am trying to make two dropdownlists where the selectable values of the second dropdownlist will be depending on what is selected on the first one.

For example: 

Dropdown 1                 Dropdown 2                   

xxx                =>             01-15    ("01" , "02" ,"03" , ...)                    
yyy                =>             a - f       ("a" , "b" ,"c" ,"d" ,"e" ,"f" ) 
zzz                =>             "new", "old", "spare"

 

I started with this code that I've found in this Forum:

#include <GUIConstantsEx.au3>

; Here is the array
Global $aArray[6] = ["SORT", "PCM", "UNIF", "KKE", "GMS", "CDY"]

; 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("DropDown", 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
 

 

Any idea how to start on this one...

thanks upfront

 

 

 

Share this post


Link to post
Share on other sites
AutoBert

here a small demo with 2 comboboxes:

#Include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <array.au3>
#include <File.au3>

Const $sCSV = @AppDataDir & "\2cbo.CSV"
Const $sElect = "bitte auswählen"
Dim $a_sCSV, $aSplit, $scboChr = ""
_FileReadToArray($sCSV,$a_sCSV)
Dim $aCSV[$a_sCSV[0]][2]
for $i = 1 to UBound($a_sCSV) - 1
    ConsoleWrite($i & $a_sCSV[$i] & @CRLF)
    $aSplit = StringSplit($a_sCSV[$i],";")
    if not StringInStr($scboChr,$aSplit[1]) Then $scboChr &= $aSplit[1] & "|"
    $aCSV[$i-1][0] = $aSplit[1]
    $aCSV[$i-1][1] = $aSplit[2]
Next
ConsoleWrite($scboChr & @CRLF)

$hGui = GUICreate("2 Comboboxen aus 1er CSV ", 250, 120, 302, 218)
$hcboChr = GUICtrlCreateCombo($sElect, 8, 8, 200, 25)
GUICtrlSetData(-1,$scboChr)
$hcboChrNr  = GUICtrlCreateCombo("",8,35,200,25)
$hbtnExit = GUICtrlCreateButton("Be&enden", 8, 65)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $hbtnExit
            Exit
        Case $hcboChr
            $sVal = GUICtrlRead($hcboChr)
            if $sVal <> $sElect Then
                $aSplit = _ArrayFindAll($aCSV,$sVal,0,0,True,True,0)
                GUICtrlSetData($hcboChrNr,"")
                $scboChr = ""
                for $i = 0 to UBound($aSplit) - 1
                    $scboChr &= $aCSV[$aSplit[$i]][1] & "|"
                Next
                ConsoleWrite($scboChr & @CRLF)
                GUICtrlSetData($hcboChrNr,$scboChr)
                _GUICtrlComboBox_SetCurSel($hcboChrNr, 0)
            EndIf
    EndSwitch
WEnd

And here is the csv:

Auto;Felgen
Werkzeug;BitSätze
Werkzeug;Schraubenschlüssel
Auto;Reifen
Zubehör;Enteiserspray

which must be in @AppDataDir.

Share this post


Link to post
Share on other sites
Joep86

Hi , 

Thanks a lot ! Do you have any idea how I could the values not in csv but xml format ?

and in stead of typing full xxx;01 / xxx;02 / xxx;03 /... that I can say range for xxx is from 01 to 05 for example

Share this post


Link to post
Share on other sites
kylomas

Joep86,

Please post an example of your XML file.

6 hours ago, Joep86 said:

and in stead of typing full xxx;01 / xxx;02 / xxx;03 /...

Typing it where, for what?

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
Joep86

Hi , 

I would like to read out parameters for a dropdown list from a xml file ? 

in example above it's done through a csv file , how is it possible to do this then with xml ?

let say I have a parameter like this in the xml file :

<ScanP_ProcessNameKill>


-<Input>

<string>SC{0:n8}.{1:n}.</string>

</Input>

<OutPut>{0}.{1:000}</OutPut>

</ScanP_ProcessNameKill>>>

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

  • Similar Content

    • therks
      By therks
      So I'm needing a (better) way to get the selection in an edit control, while knowing which end of the selection is active vs anchor (ie, if you're holding shift while moving with the arrow keys, which end of the selection is moving and which is not). Since _GUICtrlEdit_GetSel() only returns the start and end positions, in the order of smallest to largest, if you were to pass that back to the _GUICtrlEdit_SetSel(), the user's selection could end up "backwards".
      My solution has been this function:
      Func _GUICtrlEdit_GetSelByAnchor($hWnd) ; Get selection range with anchor in first index If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) Local $aActive, $aSelection = _GUICtrlEdit_GetSel($hWnd) ; Get base selection If $aSelection[0] <> $aSelection[1] Then ; Only proceed if actual selection range _GUICtrlEdit_SetSel($hWnd, -1, 0) ; Deselect, leaving only the active point $aActive = _GUICtrlEdit_GetSel($hWnd) ; Record the active point If $aActive[0] = $aSelection[0] Then ; If the active point is equal to the original first index ; Swap the original selection points (putting the anchor in [0] and active in [1]) $aSelection[0] = $aSelection[1] $aSelection[1] = $aActive[0] EndIf _GUICtrlEdit_SetSel($hWnd, $aSelection[0], $aSelection[1]) ; Reset selection to the original points EndIf Return $aSelection EndFunc The problem with this, as you may have already guessed from the two SetSel calls, is that calling it in a tight loop causes a lot of flickering. Is there a better, more reliable way to do what I'm looking for?
    • Katie_Deely
      By Katie_Deely
      Hey
       
      I have a GUI with an edit-field and a button.
      First I write some text into the edit-field and select a part of it. After that I press the button, and the selection is edited.
      How would I do that, though? When the text is selected and I press the button, it's unselected before the button actually raises an event. 
    • jloyzaga
      By jloyzaga
      I'm trying to read an excel spreadsheet(SWW_TestFlow, Worksheet=Controller) and creating a dropdown list from all the cell values within a specific column("G").   
      I would like to have the dropdown behave in such a way as to allow multiple selections and for all those selections to be written to a file.
      I attached a file I started with to experiment with gui and controls etc but got totally lost.......
      Can somebody help me?
      Joe
      multi-new.au3
    • Cormin
      By Cormin
      I've never worked with an array or dropdown menu before and I can't seem to wrap it around my head this morning.  Maybe I just need more coffee but I'm trying to populate a GUI dropdown menu with section names of a .ini file.  Here is what I have for this part but I don't know where to go from here.  The msgbox thing was only testing it but I kinda got stuck here.
       
      local $aSectionnames = IniReadSectionNames(@DesktopDir & "\Scripts\BatteryConfig.ini") if Not @error Then For $i = 1 to $aSectionnames[0] MsgBox($MB_SYSTEMMODAL, "Test", $aSectionnames[$i]) Next EndIf  
      Here is my very basic dropdown menu I want to populate
       
      #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 413, 213, 192, 124) $Combo1 = GUICtrlCreateCombo("Combo1", 80, 24, 241, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) $Button1 = GUICtrlCreateButton("Button1", 152, 56, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd  
       
      Thanks!
    • oddlogic
      By oddlogic
      I was working with an intranet site today and there is a huge combo box that you can click on where it says "All", underneath 'Model' (Capture.png). After selecting a model, there are numerous lines to choose from that do other things, which I can work with perfectly well. I have to deal with other pages similar to this one, but on this particular page the only "firing" event is the choice of the dropdown menu. 
      Here is the source for that particular field:  (The id we care about is "cphBody_rgdModelDrawing_ctl00_ctl02_ctl02_rcbModel")
      <table cellspacing="0" class="rgMasterTable" id="cphBody_rgdModelDrawing_ctl00" style="width:100%;table-layout:auto;empty-cells:show;"> <colgroup> <col /> <col /> <col /> <col /> <col style="width:45px" /> <col style="width:30px" /> </colgroup> <thead> <tr> <th scope="col" class="rgHeader"><a title="Click here to sort" href="javascript:__doPostBack(&#39;ctl00$cphBody$rgdModelDrawing$ctl00$ctl02$ctl01$ctl01&#39;,&#39;&#39;)">Model</a></th><th scope="col" class="rgHeader"><a title="Click here to sort" href="javascript:__doPostBack(&#39;ctl00$cphBody$rgdModelDrawing$ctl00$ctl02$ctl01$ctl02&#39;,&#39;&#39;)">Drawing</a></th><th scope="col" class="rgHeader"><a title="Click here to sort" href="javascript:__doPostBack(&#39;ctl00$cphBody$rgdModelDrawing$ctl00$ctl02$ctl01$ctl03&#39;,&#39;&#39;)">Station Number</a></th><th scope="col" class="rgHeader"><a title="Click here to sort" href="javascript:__doPostBack(&#39;ctl00$cphBody$rgdModelDrawing$ctl00$ctl02$ctl01$ctl04&#39;,&#39;&#39;)">Sort Order</a></th><th scope="col" class="rgHeader">&nbsp;</th><th scope="col" class="rgHeader">&nbsp;</th> </tr><tr class="rgFilterRow"> <td style="white-space:nowrap;"> <div id="cphBody_rgdModelDrawing_ctl00_ctl02_ctl02_rcbModel" class="RadComboBox RadComboBox_Default" style="width:200px;"> <table summary="combobox" style="border-width:0;border-collapse:collapse;table-layout:fixed;width:100%"> <tr class="rcbReadOnly"> <td style="margin-top:-1px;margin-bottom:-1px;width:100%;" class="rcbInputCell rcbInputCellLeft"><input name="ctl00$cphBody$rgdModelDrawing$ctl00$ctl02$ctl02$rcbModel" type="text" class="rcbInput" id="cphBody_rgdModelDrawing_ctl00_ctl02_ctl02_rcbModel_Input" value="All" style="display: block;" readonly="readonly" /></td> <td style="margin-top:-1px;margin-bottom:-1px;" class="rcbArrowCell rcbArrowCellRight"><a id="cphBody_rgdModelDrawing_ctl00_ctl02_ctl02_rcbModel_Arrow" style="overflow: hidden;display: block;position: relative;outline: none;">select</a></td> </tr> </table> <div class="rcbSlide" style="z-index:6000;"><div id="cphBody_rgdModelDrawing_ctl00_ctl02_ctl02_rcbModel_DropDown" class="RadComboBoxDropDown RadComboBoxDropDown_Default " style="float:left;display:none;"><div class="rcbScroll rcbWidth" style="height:200px;width:100%;"><ul class="rcbList" style="list-style:none;margin:0;padding:0;zoom:1;"><li class="rcbItem ">All</li><li class="rcbItem ">019-208-17-3Y</li><li class="rcbItem ">019-208-17-6Y</li><li class="rcbItem ">124-ATR-3/0-L10</li><li class="rcbItem ">124-ATR-3/0-L10M</li><li class="rcbItem ">124-ATR-3/0-L10S</li><li class="rcbItem ">124-ATR-3/0-L13</li><li class="rcbItem ">124-ATR-3/0-L15</li><li class="rcbItem ">124-ATR-3/0-L15M</li><li class="rcbItem ">124-ATR-3/0-L15S</li><li class="rcbItem ">124-ATR-3/0-L18</li><li class="rcbItem ">124-ATR-3/0-L20</li><li class="rcbItem ">124-ATR-3/0-L25</li><li class="rcbItem ">124-ATR-3/0-L30</li><li class="rcbItem ">124-ATR-4/0-L10</li><li class="rcbItem ">124-ATR-4/0-L13</li> .....there are thousands of these parts, listed like this. then at the end of the li tag list.... <script type="text/javascript"> function ModelIndexChanged(sender, args) { var tableView = $find("cphBody_rgdModelDrawing_ctl00"); tableView.filter("ModelDrawing_ModelID", args.get_item().get_value(), "EqualTo"); } </script>  
      I am able to read and write to the dropdown using either _IEGetFormCollection (by index because the page always has the same input indices) or _IEGetObjectById, and then using _IEFormElementSetValue. What I cannot seem to do is to use the "child" method whereby one would address the list object by using _IEFormGetCollection. That returns an error code of either 7 or 2 (it's been a long day. I forget which)
      The problem with writing to the dropdown with setValue is that the form doesn't fire after you change the list box. In fact, it won't even fire if a user clicks on it, then hits return. It is only by changing the value manually and then changing it again that you can get the part number that you want to display as it should. 
      How should one go about selecting the dropdown value that would allow the page to fire as it should? 
       

      ;this works but doesn't fire - I use formCollection because there are other things that I have to use fields for in this document and the indices don't change Local $oForm = _IEFormGetCollection($oIE, 0) $modelTextBox = _IEFormElementGetCollection($oForm, 7) _IEFormElementSetValue($modelTextBox, $chargerPartNumber)  
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.