Jump to content

Disabling item in Combox


Recommended Posts

Hi all,

While I do see search results for this question, most are several years old. I'm hoping there's a UDF or other new change that will allow this since it appears to be possible in other languages. I'm not seeing anything in the help file but maybe there's something I'm missing somewhere 🤞?

Anyway, is there a way to disable selection of an item in a ComboBox now?

Thanks in advance!

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco Finesse, Github, IRC UDF, WindowEx UDF

 

Link to comment
Share on other sites

Depends on what you mean by disable a selection within a combo box, just change the event for that selection, for example:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Example", 300, 200)

    ; Create a combobox control.
    Local $idComboBox = GUICtrlCreateCombo("Item 1", 10, 10, 185, 20)
    Local $idButton_Close = GUICtrlCreateButton("Close", 210, 170, 85, 25)

    ; Add additional items to the combobox.
    GUICtrlSetData($idComboBox, "Item 2|Item 3|Item 4", "Item 1")

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    Local $sComboRead = ""

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idButton_Close
                ExitLoop
            Case $idComboBox
                $sComboRead = GUICtrlRead($idComboBox)
                ;~ Item 3 does nothing
                If GUICtrlRead($idComboBox) = "Item 3" Then ContinueLoop
                If GUICtrlRead($idComboBox) = "Item 4" Then
                    MsgBox(4096, "", "Item 4 is disabled")
                    GUICtrlSetData($idComboBox, "Item 1")
                    ContinueLoop
                EndIf
                MsgBox($MB_SYSTEMMODAL, "", "The combobox is currently displaying: " & $sComboRead, 0, $hGUI)
        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example

 

Link to comment
Share on other sites

11 hours ago, Subz said:

Depends on what you mean by disable a selection within a combo box, just change the event for that selection, for example.


That's one way to do it. It'd be nice to gray out the item too but I can indicate that another way using _GUICtrlComboBoxEx_SetItemImage

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco Finesse, Github, IRC UDF, WindowEx UDF

 

Link to comment
Share on other sites

  • Moderators
15 minutes ago, BigDaddyO said:

Perhaps:  GuictrlSetState($hCombo, $GUI_DISABLE)

This would disable the whole combobox, rather than just one item in it.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...