Jump to content
Sign in to follow this  
DannyJ

Dropdown list help required multiple choiches

Recommended Posts

Hello Auto It Forum,

I am trying to make dropdown menus that depend on each other and I want to make it to level 3.
For Example:
one;big;apple
one;big;banana
one;small;reference
one;small;note
two;medium;pizza;
two;medium;burger;
two;small;animal;
three;black;dog
three;black;cat
three;white;mause

Here is my example code wich is working for two items:

 

#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <array.au3>
#include <File.au3>
#include <ComboConstants.au3>
#include <WindowsConstants.au3>


Const $sCSV = @ScriptDir & "\2cbo.CSV"
Const $sElect = "Válasz"
Dim $a_sCSV, $aSplit, $scboChr = ""
_FileReadToArray($sCSV, $a_sCSV)
Dim $aCSV[$a_sCSV[0]][2]

For $i = 1 To UBound($a_sCSV) - 1

    $aSplit = StringSplit($a_sCSV[$i], ";") ; itt ; volt

    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("Komboboxok ", 250, 120, 302, 218);GUI

$hcboChr = GUICtrlCreateCombo($sElect, 8, 8, 200, 25, $CBS_DROPDOWNLIST + $WS_VSCROLL)
GUICtrlSetData($hcboChr, $scboChr) ;belerakjaa combo boxba for the last created control -1 ???

$hcboChrNr = GUICtrlCreateCombo("", 8, 35, 200, 25, $CBS_DROPDOWNLIST + $WS_VSCROLL)

$hbtnExit = GUICtrlCreateButton("&Exit", 8, 65);button

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

 

Share this post


Link to post
Share on other sites

This is my NOt working code for 3level dropdowns which depends on each other:
 

#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <array.au3>
#include <File.au3>
#include <ComboConstants.au3>
#include <WindowsConstants.au3>


Const $file = @ScriptDir & "\beolvas.txt"
Const $alapValasz = "Válasz"
Dim $belsotomb, $aSplit, $AdatElsoMenu, $aSplit2, $AdatMasodikMenu = ""
_FileReadToArray($file, $belsotomb)

Dim $kulsotomb[$belsotomb[0]][3]

For $i = 1 To UBound($belsotomb) - 1
    ConsoleWrite("$belsotomb[$i]:" & $belsotomb[$i] & @CRLF )

    ConsoleWrite(@CRLF & $i & " Első szétv" & @CRLF)
    $aSplit = StringSplit($belsotomb[$i], ";") ;
    ConsoleWrite("$aSplit[1]: " & $aSplit[1] & @CRLF)

    If Not StringInStr($AdatElsoMenu, $aSplit[1]) Then $AdatElsoMenu &= $aSplit[1] & "|"
    ConsoleWrite("$AdatElsoMenu: "  & $AdatElsoMenu & @CRLF)

    $kulsotomb[$i - 1][0] = $aSplit[1]
    ConsoleWrite( "$kulsotomb[$i - 1][0] = $aSplit[1]" & $kulsotomb[$i - 1][0] & "=" & $aSplit[1] & @CRLF)
    $kulsotomb[$i - 1][1] = $aSplit[2]
    ConsoleWrite( "$kulsotomb[$i - 1][1] = $aSplit[2]" & $kulsotomb[$i - 1][1] & "=" & $aSplit[2] & @CRLF)

    ConsoleWrite(@CRLF & $i & " Második szétv" & @CRLF)
    ;2dik szétvászaltás
    $aSplit2 = StringSplit($belsotomb[$i], ";")
    If Not StringInStr($AdatMasodikMenu, $aSplit2[2]) Then  $AdatMasodikMenu &=  $aSplit2[2] & "|"
    ConsoleWrite("$Adat2Menu: "  & $AdatMasodikMenu & @CRLF)

    $kulsotomb[$i][1] = $aSplit2[2]
    ConsoleWrite( "$kulsotomb[$i - 1][0] = $aSplit[1]" & $kulsotomb[$i][1] & "=" & $aSplit2[2] & @CRLF)
    $kulsotomb[$i][2] = $aSplit2[3]
    ConsoleWrite( "$kulsotomb[$i - 1][1] = $aSplit[2]" & $kulsotomb[$i][2] & "=" & $aSplit2[3] & @CRLF)


Next
ConsoleWrite("$AdatElsoMenu: " &$AdatElsoMenu  & @CRLF)
ConsoleWrite("AdatmasodikMenu: " & $AdatMasodikMenu)

;
;ConsoleWrite("Kulso tombok" & @CRLF & @CRLF)
;For $i = 0 To UBound($kulsotomb) - 1
;   ConsoleWrite($kulsotomb[$i][0] & " ") első oszlop
;Next

;For $i = 0 To UBound($kulsotomb) - 1
;   ConsoleWrite($kulsotomb[$i][1] & " ")
;Next
;ConsoleWrite(@CRLF & "Kulso tombok" & @CRLF & @CRLF)


$hGui = GUICreate("Komboboxok ", 250, 420, 302, 218);GUI

$elsolegordulo = GUICtrlCreateCombo($alapValasz, 8, 8, 200, 25, $CBS_DROPDOWNLIST + $WS_VSCROLL)
GUICtrlSetData($elsolegordulo, $AdatElsoMenu) ;belerakjaa combo boxba for the last created control -1 ???

$masodiklegordulo = GUICtrlCreateCombo("", 8, 35, 200, 25, $CBS_DROPDOWNLIST + $WS_VSCROLL)

$harmadiklegordulo = GUICtrlCreateCombo("", 8, 65, 200, 25, $CBS_DROPDOWNLIST + $WS_VSCROLL)
$kilepgomb = GUICtrlCreateButton("&Exit", 8, 155);button

GUISetState(@SW_SHOW)
$elsoadat = GUICtrlRead($elsolegordulo )
ConsoleWrite("$elsoadat" & $elsoadat & @CRLF)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $kilepgomb
            Exit
        Case $elsolegordulo
            $elsoadat = GUICtrlRead($elsolegordulo )
            ConsoleWrite("$elsoadat: " & $elsoadat & @CRLF )
            If $elsoadat <> $alapValasz Then
                $aSplit = _ArrayFindAll($kulsotomb, $elsoadat, 0, 0, True, True, 0)
                ConsoleWrite("$aSplit " & $aSplit  & @CRLF)

                GUICtrlSetData($masodiklegordulo, "")
                $AdatElsoMenu = ""

                For $i = 0 To UBound($aSplit) - 1
                    $AdatElsoMenu &= $kulsotomb[$aSplit[$i]][1] & "|"
                Next
                ConsoleWrite("$AdatElsoMenu: " & $AdatElsoMenu & @CRLF)
                GUICtrlSetData($masodiklegordulo, $AdatElsoMenu)
                ConsoleWrite("$masodiklegordulo " & $masodiklegordulo  & @CRLF)
                _GUICtrlComboBox_SetCurSel($masodiklegordulo, 0)
            EndIf
                ;második legördulő
            Case $masodiklegordulo
            $masodiksoadat = GUICtrlRead($masodiklegordulo )
            ConsoleWrite("$elsoadat: " & $masodiksoadat & @CRLF )
            If $masodiksoadat <> $alapValasz Then
                $aSplit2 = _ArrayFindAll($kulsotomb, $masodiksoadat, 0, 0, True, True, 0)
                ConsoleWrite("$aSplit " & $aSplit2  & @CRLF)

                GUICtrlSetData($masodiklegordulo, "")
                $AdatElsoMenu = ""

                For $i = 0 To UBound($aSplit) - 1
                    $AdatElsoMenu &= $kulsotomb[$aSplit2[$i]][1] & "|"
                Next
                ConsoleWrite("$AdatElsoMenu: " & $AdatElsoMenu & @CRLF)
                GUICtrlSetData($harmadiklegordulo, $AdatElsoMenu)
                ConsoleWrite("$masodiklegordulo " & $harmadiklegordulo  & @CRLF)
                _GUICtrlComboBox_SetCurSel($harmadiklegordulo, 0)

            EndIf
    EndSwitch
WEnd

 

Share this post


Link to post
Share on other sites

@DannyJ
One of many ways to do it:

#include <ComboConstants.au3>
#include <GuiComboBox.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $arrComboBoxes[3]

#Region ### START Koda GUI section ### Form=
Global $frmComboBoxes = GUICreate("ComboBoxes", 250, 128, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "ExitApplication")
$arrComboBoxes[0] = GUICtrlCreateCombo("", 20, 19, 209, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
GUICtrlSetFont(-1, 10, 400, 0, "Arial")
$arrComboBoxes[1] = GUICtrlCreateCombo("", 20, 51, 209, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
GUICtrlSetFont(-1, 10, 400, 0, "Arial")
$arrComboBoxes[2] = GUICtrlCreateCombo("", 20, 83, 209, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
GUICtrlSetFont(-1, 10, 400, 0, "Arial")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $strFileName = @ScriptDir & "\ComboBoxes.csv", _
       $arrFileContent

_FileReadToArray($strFileName, $arrFileContent, $FRTA_COUNT, ";")
If @error Then
    ConsoleWrite("_FileReadToArray ERR: " & @error & @CRLF)
Else
    ; Fill the first ComboBox with the array elements of the "first level"
    For $i = 1 To $arrFileContent[0][0] Step 1
        GUICtrlSetData($arrComboBoxes[0], $arrFileContent[$i][0] & ($i < $arrFileContent[$i][0] ? "|" : ""))
    Next

    ; Set the current selection to the first enrty of the ComboBox
    _GUICtrlComboBox_SetCurSel($arrComboBoxes[0], 0)
EndIf

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $arrComboBoxes[0]
            FillCombo($arrComboBoxes[0], 0)
        Case $arrComboBoxes[1]
            FillCombo($arrComboBoxes[1], 1)


    EndSwitch
WEnd

Func FillCombo($idCombo, $intComboBoxLevel)

    Local $strComboData = "", _
          $arrIndexes, _
          $arrEntries[0]

    $strComboData = GUICtrlRead($idCombo)
    $arrIndexes = _ArrayFindAll($arrFileContent, $strComboData, 0, 0, 0, 0, $intComboBoxLevel)
    If IsArray($arrIndexes) Then

        ; Blank all the other ComboBoxes which are on the next level(s)
        For $i = UBound($arrComboBoxes) - 1 To $intComboBoxLevel + 1 Step -1
            GUICtrlSetData($arrComboBoxes[$i], "")
        Next

        ; Find all occurences of the ComboBox item selected
        For $i = 0 To UBound($arrIndexes) - 1 Step 1
            _ArrayAdd($arrEntries, $arrFileContent[$arrIndexes[$i]][$intComboBoxLevel + 1])
        Next

        ; Make all entries found unique
        $arrEntries = _ArrayUnique($arrEntries, 0, 0, 0, $ARRAYUNIQUE_NOCOUNT)

        ; Fill the ComboBox
        For $i = 0 To UBound($arrEntries) - 1 Step 1
            GUICtrlSetData($arrComboBoxes[$intComboBoxLevel + 1], $arrEntries[$i] & "|")
        Next

        _GUICtrlComboBox_SetCurSel($arrComboBoxes[$intComboBoxLevel + 1], 0)

    EndIf

EndFunc

Func ExitApplication()
    Exit
EndFunc

:)


Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...