Jump to content
Sign in to follow this  
Lupo73

One combo dependent to another

Recommended Posts

Lupo73

Is it possible to connect two combobox and change items in a combo depending to the selected item of another? A sort of selection and subselection: the user select the archive format in the first combo (zip, 7z...) and than select the compression method in the second one (the list of methods is different for each format).

I'm trying to use this example, recreating the second combo as event (and not updating a label as the example). But in my case it refresh the second combo each time mouse is hover the first one and doesn't allow to show the list of items in the combo itself. I think the problem is that I need to update the second combo when a new item is selected and not when the combo is selected.

Thanks for your help!


SFTPEx, AutoCompleteInput_DateTimeStandard(), _ImageWriteResize()_GUIGraduallyHide(): some AutoIt functions.

Lupo PenSuite: all-in-one and completely free selection of portable programs and games.

DropIt: a personal assistant to automatically manage your files.

ArcThemALL!: application to multi-archive your files and folders.

Share this post


Link to post
Share on other sites
KaFu

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

GUICreate("My GUI")

$cCombo1 = GUICtrlCreateCombo("7z", 10, 10)
GUICtrlSetData(-1, "zip|rar", "7z")

$cCombo2 = GUICtrlCreateCombo("7z - CM1", 10, 40)
GUICtrlSetData(-1, "7z - CM2|7z - CM3", "7z - CM1")

GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
GUISetState(@SW_SHOW) ; will display an empty dialog box

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
GUIDelete()


Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    $nNotifyCode = BitShift($wParam, 16)
    $nID = BitAND($wParam, 0x0000FFFF)
    $hCtrl = $lParam

    if $nID = $cCombo1 Then
        Switch GUICtrlRead($nID)
            Case "7z"
                GUICtrlSetData($cCombo2,"|7z - CM1|7z - CM2|7z - CM3","7z - CM1")
            Case "zip"
                GUICtrlSetData($cCombo2,"|zip - CM1|zip - CM2|zip - CM3","zip - CM1")
            Case "rar"
                GUICtrlSetData($cCombo2,"|rar - CM1|rar - CM2|rar - CM3","rar - CM1")
        EndSwitch
    endif

    Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_COMMAND

Share this post


Link to post
Share on other sites
Lupo73

Really thanks! It is the solution I was looking for..


SFTPEx, AutoCompleteInput_DateTimeStandard(), _ImageWriteResize()_GUIGraduallyHide(): some AutoIt functions.

Lupo PenSuite: all-in-one and completely free selection of portable programs and games.

DropIt: a personal assistant to automatically manage your files.

ArcThemALL!: application to multi-archive your files and folders.

Share this post


Link to post
Share on other sites
Lupo73

I have implemented your code in my software. It works fine, but I have a secondary issue: the selection of the first combobox influences also a button visibility, but the button seems to be recreated when combobox is clicked (the button disappears and reappears with the click).

What could be the problem? Is there a way to bypass this issue? thanks again..

Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
  Local $format, $status, $nNotifyCode, $nID, $hCtrl
  $nNotifyCode = BitShift($wParam, 16)
  $nID = BitAND($wParam, 0x0000FFFF)
  $hCtrl = $lParam
  If $nID = $ComboType Then
    $format = GUICtrlRead($nID)
    Switch $format
      Case "upx"
        GUICtrlSetData($ComboMode, $upxL, $upxM1)
        $status = $GUI_DISABLE

      Case "mpress"
        GUICtrlSetData($ComboMode, $upxL, $upxM1)
        $status = $GUI_DISABLE
                
      Case "zip", "7z"
        GUICtrlSetData($ComboMode, $zipL, $zipM1)
        $status = $GUI_ENABLE
                
      Case "archives"
        GUICtrlSetData($ComboMode, $unzL, $unzM1)
        $status = $GUI_ENABLE
                
    EndSwitch
    If $format = "archives" Then $format = "zip"
    IniWrite($sIni, "Options", "Format", $format)
    GUICtrlSetState($out, $status)
  EndIf
  Return $GUI_RUNDEFMSG
EndFunc

SFTPEx, AutoCompleteInput_DateTimeStandard(), _ImageWriteResize()_GUIGraduallyHide(): some AutoIt functions.

Lupo PenSuite: all-in-one and completely free selection of portable programs and games.

DropIt: a personal assistant to automatically manage your files.

ArcThemALL!: application to multi-archive your files and folders.

Share this post


Link to post
Share on other sites
Melba23

Lupo73 ,

I use a different method to link the combos than Kafu (although his is sexier!) - I have added a few button visibility lines to show how I would do that as well: :P

#include <GUIConstantsEx.au3>
#include <GUIComboBox.au3>

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

$hCombo_1 = GUICtrlCreateCombo("", 10, 10, 230, 20)
GUICtrlSetData(-1, "One|Two|Three")

$hCombo_2 = GUICtrlCreateCombo("", 260, 10, 230, 20)
GUICtrlSetState(-1, $GUI_DISABLE)

$hButton_1 = GUICtrlCreateButton("Test 1", 10, 100, 80, 30)
GUICtrlSetState(-1, $GUI_HIDE)
$hButton_2 = GUICtrlCreateButton("Test 2", 100, 100, 80, 30)
GUICtrlSetState(-1, $GUI_HIDE)
$hButton_3 = GUICtrlCreateButton("Test 3", 190, 100, 80, 30)
GUICtrlSetState(-1, $GUI_HIDE)
$hButton_Reset = GUICtrlCreateButton("Reset", 280, 100, 80, 30)

GUISetState()

$sCurrCombo_1 = ""

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton_Reset
            For $i = $hButton_1 To $hButton_Reset
            GUICtrlSetState($i, $GUI_HIDE)
        Next
        $sCurrCombo_1 = ""
        _GUICtrlComboBox_SetEditText($hCombo_1, "")
        _GUICtrlComboBox_SetEditText($hCombo_2, "")
        GUICtrlSetState($hCombo_2, $GUI_DISABLE)
    EndSwitch

    If GUICtrlRead($hCombo_1) <> $sCurrCombo_1 And _GUICtrlComboBox_GetDroppedState($hCombo_1) = False Then
        For $i = $hButton_1 To $hButton_3
            GUICtrlSetState($i, $GUI_HIDE)
        Next
        GUICtrlSetState($hButton_Reset, $GUI_SHOW)
        $sCurrCombo_1 = GUICtrlRead($hCombo_1)
        Switch $sCurrCombo_1
            Case "One"
                GUICtrlSetData($hCombo_2, "|A|B|C")
                GUICtrlSetState($hButton_1, $GUI_SHOW)
            Case "Two"
                GUICtrlSetData($hCombo_2, "|D|E|F")
                GUICtrlSetState($hButton_2, $GUI_SHOW)
            Case "Three"
                GUICtrlSetData($hCombo_2, "|G|H|I")
                GUICtrlSetState($hButton_3, $GUI_SHOW)
        EndSwitch
        GUICtrlSetState($hCombo_2, $GUI_ENABLE)
    EndIf

WEnd

Does it help at all? :mellow:

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
KaFu

I have implemented your code in my software. It works fine, but I have a secondary issue: the selection of the first combobox influences also a button visibility, but the button seems to be recreated when combobox is clicked (the button disappears and reappears with the click).

Shouldn't

GUICtrlSetState($out, $status)

be something more like

GUICtrlSetState($ComboMode, $status)

? I don't see $out decleared in your snippet...

Share this post


Link to post
Share on other sites
Lupo73

It's good also your second solution, Melba23.. Is there any relevant difference to use it instead of the previous one? (I have already implemented the first solution in my software)

I have also resolved the second issue, moving externally the enabling/disabling button operation.

Thanks!


SFTPEx, AutoCompleteInput_DateTimeStandard(), _ImageWriteResize()_GUIGraduallyHide(): some AutoIt functions.

Lupo PenSuite: all-in-one and completely free selection of portable programs and games.

DropIt: a personal assistant to automatically manage your files.

ArcThemALL!: application to multi-archive your files and folders.

Share this post


Link to post
Share on other sites
Melba23

Lupo73,

Is there any relevant difference

If the end result is the same, a logical positivist like me would say "No". :party:

But as I said above, Kafu's code is "sexier" because it uses the Windows message stream while I am "polling in the While...WEnd loop" which some (no names of course!) have been know to classify as a bit "sad". However, as I mentioned above, if it works........ :P

You choose which you prefer. :mellow:

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
Lupo73

But as I said above, Kafu's code is "sexier" because it uses the Windows message stream while I am "polling in the While...WEnd loop" which some (no names of course!) have been know to classify as a bit "sad". However, as I mentioned above, if it works........ :P

Thank you very much for the code and the really good answer :mellow:


SFTPEx, AutoCompleteInput_DateTimeStandard(), _ImageWriteResize()_GUIGraduallyHide(): some AutoIt functions.

Lupo PenSuite: all-in-one and completely free selection of portable programs and games.

DropIt: a personal assistant to automatically manage your files.

ArcThemALL!: application to multi-archive your files and folders.

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  

×

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.