Jump to content
Reher

Changing Comboboxstyle from $CBS_DROPDOWN to $CBS_DROPDOWNLIST

Recommended Posts

Hi

so i ran into a Problem i didn't expect to get stuck on.:sweating:

It sounds simple (and probably is) but i can't seem to get it to work

So i created a Combobox and filled it with some things from an array which worked fine.

$combobox = GUICtrlCreateCombo($list[0], 160, 200, 265, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GuiCtrlSetData($list, "|" & _ArrayToString($list,Default,1),$list[2])
GUICtrlSetFont(-1, 9, 400, 0, "Arial")

Now i want to change the style of the combobox from $CBS_DROPDOWN to $CBS_DROPDOWNLIST via a checkbox.

$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 160, 96, 105, 25)

Case $Checkbox1
            If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
            Call ("Read_only")
            Else
            Call ("Edit")
            Endif 
            

Func Read_only()
    GUICtrlSetStyle ($Combobox1,something to change it to $CBS_DROPDOWNLIST)
EndFunc

Func Edit()
    GUICtrlSetStyle ($Combobox1,something to change it to $CBS_DROPDOW)
EndFunc

I tried using $CBS_DROPDOWN and $CBS_DROPDOWNLIST but it simply does nothing.
I also tried $ES_READONLY which kinda worked, it changed the combobox so i couldn't change the input via dropdown anymore but i could still type in it via keyboard (which i dont want).
It's essential that its Editable but once the checkbox is checked the combobox becomes readonly so you can't type in it anymore but you can still choose between the items in the list. (It does not have to save your current input if you write something in it and then check the Checkbox it would be best if it would simpy jump back to the first item in the list)

Im sure this is a simple thing but after long google search im tired of my stupidity can someone give me a push in the right direction?

Edited by Reher

Share this post


Link to post
Share on other sites

I don't believe this can be done, the closest thing I can think of is the following:

Global $idComboBox
...
..
.
$idComboBox = GUICtrlCreateCombo($aComboList[0], 10, 10, 185, 20, $CBS_DROPDOWN)
GuiCtrlSetData($idComboBox, _ArrayToString($aComboList),$aComboList[2])
...
..
.
Case $idCheckBox
    If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
        Read_only(True)
    Else
        Read_only(False)
    Endif
...
..
.
Func Read_only($bReadOnly = False)
    Local $sComboBox = GUICtrlRead($idComboBox)
    Local $aComboBox = _GUICtrlComboBox_GetListArray($idComboBox)
    Local $iComboStyle = $bReadOnly ? $CBS_DROPDOWNLIST : $CBS_DROPDOWN
    GUICtrlDelete($idComboBox)
    $idComboBox = GUICtrlCreateCombo("", 10, 10, 185, 20, $iComboStyle)
    GUICtrlSetData($idComboBox, _ArrayToString($aComboBox, "|", 1), $sComboBox)
EndFunc

 

Share this post


Link to post
Share on other sites

@dmob Thought of that at first, but you would lose any added entries, added during edit mode.  So you would have to copy the contents between each combo box.  Thought this method would be easier.

Share this post


Link to post
Share on other sites

That is true, but seems the OP does not mind that?

10 hours ago, Reher said:

 (It does not have to save your current input if you write something in it and then check the Checkbox it would be best if it would simpy jump back to the first item in the list)

Your method is better though, should he need to change to preserve new entries.

Share this post


Link to post
Share on other sites
12 hours ago, Subz said:

I don't believe this can be done, the closest thing I can think of is the following:

Oh i was sure it would only be my ignorance not a language restriction i was running into...

 

6 hours ago, dmob said:

Another way would be to create both then hide/unhide based on checkbox.

i tought of that aswell, but was certain there would be a more elegant solution to this. Guess i have to play the old smoke and mirror trick and just change between 2 comboboxes. I will paste my workaround later thanks for your help anyways guys^_^

 

Share this post


Link to post
Share on other sites
22 hours ago, Reher said:

I will paste my workaround later

Whoops, well i guess better late then never.

 

$Combobox = GUICtrlCreateCombo($list[0], 160, 200, 265, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GuiCtrlSetData(-1, "|" & _ArrayToString($list,Default,1),$list[2])
GUICtrlSetFont(-1, 9, 400, 0, "Arial")
GUICtrlSetState (-1, $GUI_SHOW)

$iCombobox = GUICtrlCreateCombo($list[0], 160, 200, 265, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
GuiCtrlSetData(-1, "|" & _ArrayToString($list,Default,1),$list[2])
GUICtrlSetFont(-1, 9, 400, 0, "Arial")
GUICtrlSetState (-1, $GUI_HIDE)




$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 160, 96, 105, 25)

Case $Checkbox1
            If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
            Call ("Read_only")
            Else
            Call ("Edit")
            Endif 
            

Func Read_only()
        GUICtrlSetState ($Combobox, $GUI_HIDE)
        GUICtrlSetState ($iCombobox, $GUI_SHOW)
EndFunc

Func Edit()
        GUICtrlSetState ($Combobox, $GUI_SHOW)
        GUICtrlSetState ($iCombobox, $GUI_HIDE)
EndFunc

untested, just quickly thrown together from my code.
Keep in mind that it's not perfect, the combobox variants dropdown and dropdownlist differ slightly and you have to remember to read the correct combobox in your following code :sweating:.

Share this post


Link to post
Share on other sites

You dont need to use

Call ("Read_only")

  Just call function directly:

If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
    Read_only()
 Else
    Edit()
Endif

Also:

5 hours ago, Reher said:

have to remember to read the correct combobox in your following code :sweating:.

You could use:

$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 160, 96, 105, 25)

Global $cCombo

Case $Checkbox1
    If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
        Read_only()
    Else
        Edit()
    Endif 
            

Func Read_only()
        GUICtrlSetState ($Combobox, $GUI_HIDE)
        GUICtrlSetState ($iCombobox, $GUI_SHOW)
        $cCombo = $iCombobox
EndFunc

Func Edit()
        GUICtrlSetState ($Combobox, $GUI_SHOW)
        GUICtrlSetState ($iCombobox, $GUI_HIDE)
        $cCombo = $Combobox
EndFunc

then just use $cCombo in your following code.

Share this post


Link to post
Share on other sites
19 hours ago, Subz said:

Did you try my code at all?

I did and it worked like intendet, but since i have already used the method of hiding one gui item and showing the other one multiple times in my script before. I figured i wouldn't start switching it up towards the end of my project now to avoid confusion.

Anyways i realy like your Method of deleting the gui item and creating another one with the same Name. Thanks for showing me i will probably use that from now on to avoid cluttering my code with dozen of hidden gui items with different names. Also thanks for showing me how to create a switch function i could realy have needet that when starting with my project.

21 hours ago, dmob said:

Just call function directly:

21 hours ago, dmob said:

then just use $cCombo in your following code.

Also thanks for this, its so simple if someone tells you but the thought never even crossed my mind.



So all in all i realy got more out of this question then i expected :lmao:
its my first time writing code and i never realy "learned" it from an professional. I already found lots of ways i could do things cleaner or simpler from my first project, but i cant be bothered to go through 500+ lines of code to clean my beginner mess up :sweating:

Tanks both of you for helping me to get a litte bit better at coding :graduated:

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

    • By DannyJ
      Hello Forum, 
      I have one special Combo-box [with BitOR($CBS_DROPDOWNLIST, $GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE) ] and if I press one button I want to change the Combo-box's background color, and after I press Button B I want to change it to the basic settings and it not works.
      I wanna do this with one combo-box.
      I have already tried several methods and I tried  GUICtrlComboSetColors that I have found on this forum.
      (But this methods works perfectly with Cobo boxes that don't have BitOR($CBS_DROPDOWNLIST, $GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE). 
      Here is the example code
      #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= ;$CBS_DROPDOWNLIST ;$GUI_SS_DEFAULT_COMBO $Form1 = GUICreate("Form1", 504, 249, 252, 227) $Combo1 = GUICtrlCreateCombo("", 136, 24, 193, 25,BitOR($CBS_DROPDOWNLIST, $GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE)) ; I want to change this special combo's background color if I press button 1 $Button1 = GUICtrlCreateButton("Button1", 112, 96, 75, 25) $Button2 = GUICtrlCreateButton("Button2", 264, 96, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUICtrlSetData($Combo1," " & "|" & "apple" & "|" & "banana" & "|" & "cherry" ," ") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 GUICtrlSetBkColor($Combo1,0x0078D7) Case $Button2 ;Makes the original bc color GUICtrlSetBkColor($Combo1,0xFFFFFF) EndSwitch WEnd  
      Thanks you in advance your help
    • By nacerbaaziz
      Hello
      Dear Sirs, I have a question please
      About UPDown ctrl
      Where I want to adjust its format
      For example, I want to create a window to set the clock like the window in the system
      Can this be done?
      here's the example
      ______

      #include <WindowsConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <UpDownConstants.au3> goto() func Goto() local $wGoto = GUICreate("go to spissific position", 250, 180, @DesktopWidth / 2 - 192, @DesktopHeight / 2 - 235, -1) GUICtrlCreateLabel("please write a corect position to go to it", 50, 10, 220, 20) GUICtrlCreateLabel("hours", 0, 80, 100, 30) local $Inp1 = GUICtrlCreateInput("00", 0, 90, 100, 20, $ES_NUMBER + $WS_TABSTOP)     GUICtrlCreateUpdown($Inp1, $UDS_ARROWKEYS) GUICtrlSetLimit(-1, 23, 0) GUICtrlCreateLabel("minuts", 110, 80, 100, 30) local $Inp2 = GUICtrlCreateInput("00", 110, 90, 100, 20, $ES_NUMBER + $WS_TABSTOP)     GUICtrlCreateUpdown($Inp2, $UDS_ARROWKEYS) GUICtrlSetLimit(-1, 60, 0) GUICtrlCreateLabel("seconds", 220, 80, 100, 30) local $Inp3 = GUICtrlCreateInput("00", 220, 90, 100, 20, $ES_NUMBER + $WS_TABSTOP)     GUICtrlCreateUpdown($Inp3, $UDS_ARROWKEYS) GUICtrlSetLimit(-1, 60, 0) local $Ok = GUICtrlCreateButton("&ok", 0, 150, 50, 30, 0x01) local $cancel = GUICtrlCreateButton("&cancel", 200, 150, 50, 30) GUISetState(@sw_show, $WgoTo) while 1 switch GUIGetMSG() case $GUI_Event_Close, $cancel exit case $OK local $read1 = GUICtrlRead($inp1) if $read1 >= 1 then $Read1 = ($Read1*60)*60 local $read2 = GUICtrlRead($inp2) if $read2 >= 1 then $Read2 = $Read2*60 local $read3 = GUICtrlRead($inp3) GUIDelete($WgoTo) Return $read1+$read2+$read3 exit endSwitch Wend EndFunc
      ________
      What I need is to be the contents of the inputs as follows when i change the value of the UPDown CTRL
      00
      01
      02
      03
      ...
       
    • By nacerbaaziz
      Hello, dears.
      First I apologise to you for the stupid question I'm going to ask.
      is the default style for Windows created using AutoIt   a dialog box style?
      I decided to ask this question
      Because I am using a screen reader
      If i open any program that is designed using autoit, the screen reader read for example,  
      test dialog
      but If i open any other program, for example goldwave, it read goldwav only without a word dialog
      Is there a solution to this
      The code i used to create the window is:
      $hGUI = GUICreate(str("title"), 500, 420, -1, -1, BitOr($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_SYSMENU, $WS_CAPTION), BitOr($WS_EX_ACCEPTFILES,$WS_EX_LAYERED,$WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE))
      I hope to find a solution to this problem
      please Accept my greetings, and thank you very much.
    • By odaylton
      Hello everyone ,
      Text translated from Portuguese by google - please apologize for any errors

      Once again I need a light from the gurus of this wonderful website
      I am fanatic by combobox for its usability but I am not able to uncertain images within lists ...
      I know uncertain icons, and cursors but I am not able to insert gif or jpg images.
      1) How to solve this ...
      2) will the path is to convert gif into bmp and then uncertain ... how to do that?
      #include <GUIConstantsEx.au3> #include <GuiImageList.au3> #include <GuiListView.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> ;dados de mouse #include <WinAPIRes.au3> ;COMBO #include <GuiComboBoxEx.au3> ;Fonts #include <FontConstants.au3> ;obter imagem de arquivo #include <GDIPlus.au3> #include <WinAPIGdi.au3> Example() Func Example() Local $hGUI, $hImage, $hCombo, $hFont Local $idListview, $hImage Local $sWow64 = "" Local $Pasta = "C:\WINDOWS\Cursors\3dgarro.cur" Local $PastaROMs = @MyDocumentsDir & "\Stella\ROMs\" ;com barra no final $hGUI = GUICreate("ImageList", 500, 310) GUISetFont(14, 400, 0, "Arial") ;<<<<<<<<<<this does not work for _GUICtrlComboBoxEx_Create $hCombo = _GUICtrlComboBoxEx_Create($hGUI, "", 2, 2, 494, 200) ;GUICtrlSetFont($hCombo, 14, 400, 0, "Arial");<<<<<<<<<<It does not work ; ;Create a handle to a font object $hFont = _WinAPI_CreateFont(30, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Arial') ;Pass the handle to _WinAPI_SetFont _WinAPI_SetFont($hCombo, $hFont) $idListview = GUICtrlCreateListView("", 2, 50, 494, 250, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT)) _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER)) GUISetState(@SW_SHOW) ; Initialize GDI+ library _GDIPlus_Startup() ; Load images $hImage = _GUIImageList_Create(120, 70, 6, 2) ;32,32,5,5) ; $DadosCombo = "Escolha|" & _GUIImageList_Add($hImage, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, 0x0000FF, 120, 70)) ;Local $aCursors[] = [32650, 32512, 32515, 32649, 32651, 32513, 32648, 32646, 32643, 32645, 32642, 32644, 32516, 32514] For $i = 1 To 10 $sFile = FileOpenDialog("Please select an image", $PastaROMs, "Image (*.jpg;*.png;*.bmp;*.gif;*.tif)", BitOR($FD_PATHMUSTEXIST, $FD_FILEMUSTEXIST)) If @error Then Exit MsgBox(BitOR($MB_TOPMOST, $MB_ICONERROR), "Error", "No image file has been selected", 30) $a = _GDIPlus_BitmapCreateFromFile ($sFile);<<<<< ok If @error Or Not $hImage Then MsgBox(BitOR($MB_TOPMOST, $MB_ICONERROR), "Error", "This file isn't supported by GDIPlus!") Else $b=_GUIImageList_Add($hImage, $a);<<<<<< Return -1 $DadosCombo &= "|" & $i & "_img_princ.gif""|" & $b EndIf Next _GUICtrlListView_SetImageList($idListview, $hImage, 1) _GUICtrlComboBoxEx_SetImageList($hCombo, $hImage) ; Add columns _GUICtrlListView_AddColumn($idListview, "Icons - Mouses", 350) ; Add items $a = StringSplit($DadosCombo, "|") For $i = 1 To $a[0] Step 2 _GUICtrlListView_AddItem($idListview, $a[$i], $a[$i + 1]) _GUICtrlComboBoxEx_AddString($hCombo, $a[$i], $a[$i + 1], $a[$i + 1]) Next ;AutoIt_Debugger_Command:Disable_Debug ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() ;AutoIt_Debugger_Command:Enable_Debug EndFunc ;==>Example tks
    • By aiter
      I  possibly misunderstood the value of combo boxes, but I thought you could type a value, press enter and the combo box would store that value.
      The reason for wanting this is to store a history of typed commands into the combo box (accepted by pressing enter).
       
      After hours of trying to trap enter on a combobox I realized that the enter event was not registering.
      I had code like this (which used to work on a input box), but it does not for a combobox (because it does not accept enter)
      unc WM_COMMAND($hWnd, $Msg, $wParam, $lParam) Local $nNotifyCode = BitShift($wParam, 16) Local $nID = BitAND($wParam, 0x0000FFFF) If $hWnd = $CmdForm Then If $nID = $ComboInput Then ; useed to work on a normal input box If _IsPressed('0D') Then ; enter was pressed, respond DoCmd() Anyone able to help?
×
×
  • Create New...