Jump to content

Possible to disable one of the items in a combo box?


Recommended Posts

Was wondering if it was possible to disable the item "Two" in the following combobox example? The user would be allowed to select "One" and "Three" items but cannot choose "Two".

#include <GUIConstants.au3>

GUICreate("My GUI combo") ; will create a dialog box that when displayed is centered

GUICtrlCreateCombo ("", 10,10,-1,-1,$CBS_DROPDOWNLIST); create first item
GUICtrlSetData(-1,"One|Two|Three"); add other item snd set a new default

GUISetState ()

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend
Link to comment
Share on other sites

Was wondering if it was possible to disable the item "Two" in the following combobox example? The user would be allowed to select "One" and "Three" items but cannot choose "Two".

Simplest is probably not to give them the option in the first place:

GUICtrlSetData(-1,"One|Three")oÝ÷ Ø­ü¨º¯zÚ!j÷ªºS®¢Ø§¶¥Ëméò¢ç(ºW]¢Ê&zØb bëaÆ®¶­sb6æ6ÇVFRfÇC´uT6öç7FçG2æS2fwC°¢6æ6ÇVFRfÇC´6öÖ&ô6öç7FçG2æS2fwC° ¤uT7&VFRgV÷C´×uT6öÖ&ògV÷C²²vÆÂ7&VFRFÆör&÷FBvVâF7ÆVB26VçFW&V@ ¢b33c¶6öÖ&òÒuT7G&Ä7&VFT6öÖ&ògV÷C²gV÷C²ÂÃÂÓÂÓÂb33c´4%5ôE$õDõtäÄ5B²7&VFRf'7BFVФuT7G&Å6WDFFÓÂgV÷C´öæWÅGv÷ÅF&VRgV÷C²²FB÷FW"FVÒ6æB6WBæWrFVfVÇ@ ¤uT6WE7FFR £²'VâFRuTVçFÂFRFÆör26Æ÷6V@¥vÆR¢b33c¶×6rÒuTvWD×6r¢¢bb33c¶×6rÒb33c´uTôUdTåEô4Äõ4RFVâWDÆö÷¢bb33c¶×6rÒb33c¶6öÖ&òFVà¢b33cµ6VÆV7FöâÒuT7G&Å&VBb33c¶6öÖ&ò¢7vF6b33cµ6VÆV7Föà¢66RgV÷CµGvògV÷C°¢×6t&÷CÂgV÷C´çfÆB6VÆV7FöâgV÷C²Âb33µ6÷''ÂgV÷C²b33²fײb33cµ6VÆV7Föâfײb33²gV÷C²2æ÷BfÆB÷FöâBF2FÖRb33²fײð¢5$Äbfײb33µÆV6R6VÆV7Bvâb33²¢uT7G&Å6VæD×6rb33c¶6öÖ&òÂb33c´4%õ4TÄT5E5E$ärÂÓÂgV÷C´öæRgV÷C²¢uT7G&Å6VæD×6rb33c¶6öÖ&òÂb33c´44õtE$õDõtâÅG'VRâ66RVÇ6P¢¶Fò÷FW"7GVfbW&P¢VæE7vF6¢VæD`¥vVæoÝ÷ Øêé®ÚnzÛ^¯'­­é¨½ê®¢Ô𢫨µ«mÚ~׫¶²«Þ¶¸v+hǺÚ"µÍÚ[ÛYH  ÑÕRPÛÛÝ[Ë]LÉÝÂÚ[ÛYH  ÐÛÛXÐÛÛÝ[Ë]LÉÝÂÕRPÜX]J ][ÝÓ^HÕRHÛÛXÉ][ÝÊHÈÚ[ÜX]HHX[ÙÈÞ]Ú[Ü^YYÈÙ[YÌÍØÛÛXÈHÕRPÝÜX]PÛÛXÈ
    ][ÝÉ][ÝËLLLKLK  ÌÍÐÐ×ÑÔÕÓTÕ
NÈÜX]HÝ][BÕRPÝÙ]]JLK  ][ÝÓÛ_ÛßYI][ÝÊNÈYÝ][HÛÙ]H]ÈY][ÕRTÙ]Ý]H

BÈ[HÕRH[[HX[ÙÈÈÛÜÙYÚ[HB    ÌÍÛÙÈHÕRQÙ]ÙÊ
BY  ÌÍÛÙÈH ÌÍÑÕRWÑUSÐÓÔÑH[^]ÛÜY ÌÍÛÙÈH ÌÍØÛÛXÈ[  ÌÍÔÙ[XÝ[ÛHÕRPÝXY
    ÌÍØÛÛXÊBÝÚ]Ú   ÌÍÔÙ[XÝ[ÛØÙH    ][ÝÕÛÉ][ÝÂÙÐÞ
    ][ÝÒ[[YÙ[XÝ[Û][ÝË    ÌÎNÔÛÜK    ][ÝÉÌÎNÈ   [È ÌÍÔÙ[XÝ[Û [È ÌÎNÉ][ÝÈÈÝH[YÜ[Û]È[YIÌÎNÈ  [ÈÂÔ [È ÌÎNÔXÙHÙ[XÝYØZ[ÌÎNÊBÕRPÝÙ]]J   ÌÍØÛÛXË   ][ÝÉ][ÝÊBÕRPÝÙ]]J    ÌÍØÛÛXË   ][ÝÓÛ_YI][ÝË   ][ÝÓÛI][ÝÊBÕRPÝÙ[ÙÊ   ÌÍØÛÛXË   ÌÍÐÐÔÒÕÑÔÕÓYK
BØÙH[ÙBÙÈÝÝYB[ÝÚ]Ú[YÙ[
Edited by ResNullius
Link to comment
Share on other sites

ResNullius...Thanks for the quick reply...I need to have the value in the combo box at all times for the user to view but not select...Not sure if it is possible to have the following effect:

Oops..Here is the image...

post-3353-1183415331_thumb.jpg

Link to comment
Share on other sites

ResNullius...Thanks for the quick reply...I need to have the value in the combo box at all times for the user to view but not select...Not sure if it is possible to have the following effect:

I thought maybe that's what you wanted. It doesn't appear to be possible with the standard combo box control as created by GuitCtrlCreateCombo().

Some quick googling shows it may be possible with an owner-drawn combobox, but that type of thing is beyond me at this stage of my knowledge; sorry :whistle:

Anybody else up for such a challenge?

Link to comment
Share on other sites

I thought maybe that's what you wanted. It doesn't appear to be possible with the standard combo box control as created by GuitCtrlCreateCombo().

Some quick googling shows it may be possible with an owner-drawn combobox, but that type of thing is beyond me at this stage of my knowledge; sorry :whistle:

Anybody else up for such a challenge?

Thanks for trying ResNullius....Anyone else know if this is possible?

Link to comment
Share on other sites

Thanks for trying ResNullius....Anyone else know if this is possible?

You could change the list to

one

two (not available)

three

Keep a record of the last successful selection so if they select Two then just put back the last selection and give a message.

When Two becomes an option again change the text back to just "Two".

If you want a visual indication then you could produce something like this using an idea I tried for smashly

This was for colour selections.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • 1 month later...

You could change the list to

one

two (not available)

three

Keep a record of the last successful selection so if they select Two then just put back the last selection and give a message.

When Two becomes an option again change the text back to just "Two".

If you want a visual indication then you could produce something like this using an idea I tried for smashly

This was for colour selections.

Thanks for the reply Martin...How did you use the pictures in the dropdown? Second question....Is there anyway to just make one or more items in the dropdown a different color?
Link to comment
Share on other sites

Thanks for the reply Martin...How did you use the pictures in the dropdown? Second question....Is there anyway to just make one or more items in the dropdown a different color?

Without doing an Owner-Drawn combo I don't know how to have different coloured lines.

Somewhere I've seen, or I think I've seen, an example of an owner drawn combobox but I can't find it. This is what you need. It's the sort of thing Holger would write, or maybe it was someone who used ideas from Holger. The script I wrote is really awful IMO compared to a proper owner drawn version, but in case it's any use here it is. You need 2 icons in a subfolder called 'images' in the @ScriptDir. The icons need to be called 'smalblacktick.ico' and 'smallredcross.ico'. I made them 11 x 11.

;just playing

#include <GUIConstants.au3>
#include <guicombo.au3>
#include <misc.au3>
Global Const  $CBN_DROPDOWN = 7
Global Const $CBN_CLOSEUP = 8
Global Const $WM_NOTIFY = 0x004E
Global Const $WM_COMMAND = 0x0111
Global Const $CBN_EDITCHANGE = 5;
Global Const $CBN_SELCHANGE = 1;
Global Const $CBN_EDITUPDATE = 6;
$nt = 0
$top = 1
$maxdrop = 10


$Formname = "ticked pickier combobox"
$formwid=413
$formht = 280;short so that can demonstarte drop down dropping outside of form.
$Form3 = GUICreate($Formname, $formwid,$formht, 303, 249)
$ll = GUICtrlCreateLabel("jgb",10,20,120,20)
$Combo1 = GUICtrlCreateCombo("black", 145, 62, 145,20,BitOR($CBS_DROPDOWNLIST,$WS_VSCROLL))
;GUICtrlSetFont(-1,16)
$cc = "maroon|green|olive|navy|purple|teal|gray|silver|red|lime|yellow|blue|fuchsia|aqua|white"
$splitcc = StringSplit($cc,'|')
GUICtrlSetData(-1,$cc)
$cp = ControlGetPos($Formname,'',$combo1)

$bb=GUICtrlCreateButton("button",119,130)
GUICtrlCreateCheckbox("ticked Or Not",119,158)
GUICtrlCreateEdit("an edit box under the drop down area",100,180,200,100)
GUISetState(@SW_SHOW)

$ha =DllCall("user32.dll","int","GetDC","hwnd",$Form3)
GUICtrlSendMsg($combo1,$CB_SETMINVISIBLE,$maxdrop,0)
GUIRegisterMsg($WM_COMMAND,"MY_WM_COMMAND")

;work out the form border width and title height
$mfp = WinGetPos($Formname)
$borderwid = ($mfp[2]- $formwid)/2
$TitleHt = $mfp[3] - $formht - $borderwid

$itemht = _GUICtrlComboGetItemHeight($combo1,1)

;creat a Form To hold the list of colours
$containerht= $itemht*$maxdrop  + 2
$containerwid = 12
$fhide = GUICreate("container",$containerwid,$containerht,$mfp[0] + $borderwid+$cp[0] - 16,$mfp[1] + $TitleHt+$cp[1]+21,$WS_POPUP)


GUICtrlCreateGraphic(0,0,$containerwid + 1,$itemht*$maxdrop + 2)
GUICtrlSetBkColor(-1,0xFFFFFF)
GUICtrlSetColor(-1,0);0x7996DE)
Dim $gc[$maxdrop]
Dim $ic[16]
For $nn = 0 To 15;$maxdrop - 1
    
    If $nn <> 5 Then
        $ic[$nn] = GUICtrlCreateIcon("images\smalblacktick.ico",0,2, 2+$itemht*$nn, 11, 11)
    Else
        $ic[$nn] = GUICtrlCreateIcon("images\smalredcross.ico",0,2, 2+$itemht*$nn, 11, 11)
    EndIf
    
    
Next


$showic = $ic[0]


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $bb;to test when dropdown goes above combo because too near bottom of screen
            $mfp = WinGetPos($Formname)
            WinMove($Formname,'',$mfp[0],$mfp[1]+1)
    EndSwitch
WEnd

Func redrawcolos()
    $nt = _GUICtrlComboGetTopIndex($Combo1)
    #cs
    If $nt = 0 Then
        GUICtrlSetData($ll,'black')
    Else
        GUICtrlSetData($ll,$splitcc[$nt])
    EndIf
  #ce
  
    If $nt <> $top Then
        GUISwitch(WinGetHandle($fhide))
        
        
        For $nn = 0 To 15; $maxdrop - 1;$nt+1 To $nt + $maxdrop - 1
            GUICtrlSetPos($ic[$nn],2, 2+$itemht*($nn - $nt),$containerwid - 1,$itemht - 2)
            
        Next
    EndIf
    $top = $nt
    
    
EndFunc


Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    Local $nNotifyCode = _HiWord($wParam)
    Local $nID = _LoWord($wParam)
    Local $hCtrl = $lParam

    Switch $nID
        Case $combo1
            Switch $nNotifyCode
                Case $CBN_DROPDOWN
                    AdlibEnable("redrawcolos",100)
                    GUISetState(@SW_SHOW,WinGetHandle($fhide))
                    WinSetOnTop("container","",1)
                    $mfp = WinGetPos($Formname)
                    $tobottom = $mfp[1] + $TitleHt + $cp[1] + $cp[3]
                    If $tobottom > @DesktopHeight - $containerht Then
                        $shift = -$cp[3]- $containerht
                    Else
                        $shift = 0
                    EndIf

                    WinMove("container","",$mfp[0] + $borderwid + $cp[0] - $containerwid,$shift + $mfp[1] + $TitleHt + $cp[1]+$cp[3])

                Case $CBN_CLOSEUP
                    AdlibDisable()
                    #region -  see if mouse click was over chart colours
                    $nt = _GUICtrlComboGetTopIndex($Combo1)
                    ConsoleWrite("$nt = " & $nt & @CRLF)
                    $mm = MouseGetPos()
                    $ff = WinGetPos("container")
                    If Inside($ff,$mm) Then
                        _GUICtrlComboSetCurSel($combo1,$nt + Int(((-$ff[1] + $mm[1])/$ff[3])* $maxdrop))
                    EndIf
                    #endregion -see if mouse was over chart
                    GUISetState(@SW_HIDE,WinGetHandle($fhide))
                    $re = GUICtrlRead($combo1)
                    $it = _GUICtrlComboFindString($combo1,$re)
                    ConsoleWrite("$nt = " & $nt & "', $it = " & $it & @CRLF)
                    GUISwitch($Form3)
                    
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc  ;MY_WM_COMMAND


Func Inside($out,$in)
    If $in[1] >= $out[1] And $in[1] <= $out[1] + $out[3] And $in[0] >= $out[0] And $in[0] <= $out[0] + $out[2] Then
        Return True
    Else
        Return False
    EndIf
    
    
EndFunc



Func _HiWord($x)
    Return BitShift($x, 16)
EndFunc  ;==>_HiWord

Func _LoWord($x)
    Return BitAND($x, 0xFFFF)
EndFunc  ;==>_LoWord

Func _GetLastErrorMessage($DisplayMsgBox = "")
    Local $ret, $s
    Local $p = DllStructCreate("char[4096]")
    Local Const $FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000

    If @error Then Return ""

    $ret = DllCall("Kernel32.dll", "int", "GetLastError")
    $LastError = $ret[0]
    $ret = DllCall("kernel32.dll", "int", "FormatMessage", _
            "int", $FORMAT_MESSAGE_FROM_SYSTEM, _
            "ptr", 0, _
            "int", $LastError, _
            "int", 0, _
            "ptr", DllStructGetPtr($p), _
            "int", 4096, _
            "ptr", 0)
    $s = DllStructGetData($p, 1)
    If $DisplayMsgBox <> "" Then MsgBox(0, "_GetLastErrorMessage", $DisplayMsgBox & @CRLF & String($LastError) & "-" & $s)
    Return $s
EndFunc  ;==>_GetLastErrorMessage
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...