Jump to content

Combobox default text


ranhalt
 Share

Recommended Posts

New to the forum, but 3 years into AutoIT. Looking to improve my GUI skillz and I can't seem to find a straight answer on this.

I'm making several comboboxes, but need to make default text appear so users know what the boxes are for in the first place. I've tried to put the text in where I have "test", but that only puts the option in with the others, not the default. Is that how it's supposed to work and it's just not? Or is there something specific I'm missing? Thanks.

$menu1 = GuiCreate("IBM Server Build",200,600,-1,-1) ; GUI menu

$combo1 = _GUICtrlComboBox_Create($menu1, "test", 0, 400, 200, 120) ; Network location
$combo1a = _GUICtrlComboBox_AddString($combo1, "Firewall")
$combo1b = _GUICtrlComboBox_AddString($combo1, "Non-Firewall")
$combo2 = _GUICtrlComboBox_Create($menu1, "test", 0, 425, 200, 120) ; Production status
$combo2a = _GUICtrlComboBox_AddString($combo2, "Production")
$combo2b = _GUICtrlComboBox_AddString($combo2, "Non-Production")
$combo3 = _GUICtrlComboBox_Create($menu1, "test", 0, 450, 200, 120) ; Domain status
$combo3a = _GUICtrlComboBox_AddString($combo3, "Domain")
$combo3a = _GUICtrlComboBox_AddString($combo3, "Workgroup")
Link to comment
Share on other sites

The Call to AddString returns an index, which can then be used with the function

_GUICtrlComboBox_SetCurSel
That will set the currently selected Item to the specified index.

$iIndex = _GUICtrlComboBox_AddString($combo3, "test")
_GUICtrlComboBox_SetCurSel($combo3, $iIndex)

Mat

Edit: Why is the forum no longer adding links to functions from within autoit tags?

Edited by Mat
Link to comment
Share on other sites

Thanks so much, that's exactly what I needed. I'm finding a whole lot in the "Include" folder that will be of great use to me. Next, I'll be tackling GUI tabs to accommodate different situations without making the GUI larger.

BTW: How did my forum account pull my avatar? Pretty cool.

Link to comment
Share on other sites

So now, I'm looking to take this combobox a step further and create rules based on the combinations created by all the boxes. I want to give each option a unique numerical value, much like native function flags, so that I can create a conditional based on that total value.

I can easily write the function that will check the value of my $combovaltotal variable and proceed as necessary, but I don't know how to assign each combo box a value based on the current selection.

;~ Combo boxes
$combo1 = _GUICtrlComboBox_Create($menu1, "Choose network location", 0, 400, 200, 120) ; Network location
$combo1a = _GUICtrlComboBox_AddString($combo1, "Firewall") ; value = 1
$combo1b = _GUICtrlComboBox_AddString($combo1, "Non-Firewall") ; value = 2
_GUICtrlComboBox_SetCurSel($combo1, "Network location")
$combo2 = _GUICtrlComboBox_Create($menu1, "Choose production status", 0, 425, 200, 120) ; Production status
$combo2a = _GUICtrlComboBox_AddString($combo2, "Production") ; value = 4
$combo2b = _GUICtrlComboBox_AddString($combo2, "Non-Production") ; value = 8
_GUICtrlComboBox_SetCurSel($combo2, "Network location")
$combo3 = _GUICtrlComboBox_Create($menu1, "Choose domain location", 0, 450, 200, 120) ; Domain status
$combo3a = _GUICtrlComboBox_AddString($combo3, "Domain") ; value = 16
$combo3a = _GUICtrlComboBox_AddString($combo3, "Workgroup") ; value = 32
_GUICtrlComboBox_SetCurSel($combo3, "Network location")

; example $combo1a + $combo2b + $combo3a... $combovaltotal = 41
; If $combovaltotal = 41 then
;    function
; elseif $combovaltotal = 22 then
;    function
; yada yada
; endif
Edited by ranhalt
Link to comment
Share on other sites

Never mind.

$combo1 = GUICtrlCreateCombo("Choose network location", 0, 400, 200, 120) ; create first item
GUICtrlSetData($combo1, "Firewall|Non-Firewall", "") ; add other item snd set a new default
$combo2 = GUICtrlCreateCombo("Choose Production Status", 0, 425, 200, 120) ; create first item
GUICtrlSetData($combo2, "Production|Non-Production", "") ; add other item snd set a new default
$combo3 = GUICtrlCreateCombo("Choose domain location", 0, 450, 200, 120) ; create first item
GUICtrlSetData($combo3, "MOSDOM02|Workgroup", "") ; add other item snd set a new default

GUICtrlRead($combo1)
Link to comment
Share on other sites

You can use GUICtrlRead on thew combo box to get the selection as a string, and then use a Switch statement to decide what number that is:

Switch GUICtrlRead ($Combo2)
   Case "Choose production status"
      MsgBox (16, "Error", "Please Select a valid production status")
   Case "Production"
      $combovaltotal += 4
   Case "Non-Production"
      $combovaltotal += 8
EndSwitch

(This was written on the spot, so may not be perfect)

You get the idea. As an alternative, you can use "_GUICtrlComboBox_GetCurSel" and then do something with the numbers. This will probably make a much nicer solution:

$combo2val = _GUICtrlComboBox_GetCurSel ($combo2)
$combovaltotal += $combo2val * 4

Although it may be slightly more difficult to understand... As you need to know that the indexes will be exactly as you want them to be. That brings me onto my next point. Try this code instead:

$combo1 = _GUICtrlComboBox_Create($menu1, "Choose network location", 0, 400, 200, 120, $CBS_DROPDOWNLIST) ; Network location
$combo1a = _GUICtrlComboBox_AddString($combo1, "Firewall") ; value = 1
$combo1b = _GUICtrlComboBox_AddString($combo1, "Non-Firewall") ; value = 2
_GUICtrlComboBox_SetCurSel($combo1, "Network location")
$combo2 = _GUICtrlComboBox_Create($menu1, "Choose production status", 0, 425, 200, 120, $CBS_DROPDOWNLIST) ; Production status
$combo2a = _GUICtrlComboBox_AddString($combo2, "Production") ; value = 4
$combo2b = _GUICtrlComboBox_AddString($combo2, "Non-Production") ; value = 8
_GUICtrlComboBox_SetCurSel($combo2, "Network location")
$combo3 = _GUICtrlComboBox_Create($menu1, "Choose domain location", 0, 450, 200, 120, $CBS_DROPDOWNLIST) ; Domain status
$combo3a = _GUICtrlComboBox_AddString($combo3, "Domain") ; value = 16
$combo3a = _GUICtrlComboBox_AddString($combo3, "Workgroup") ; value = 32
_GUICtrlComboBox_SetCurSel($combo3, "Network location")

You will notice it does not allow the user to edit the values in the box, which is very useful if you want them to make a fixed selection.

Mat

Link to comment
Share on other sites

And since i'm away for a few days... Heres something for you to think about:

#include<GUIComboBox.au3>

$menu1 = GUICreate ("test", 800, 800)

Local $combo[4]

$combo[1] = GUICtrlCreateCombo("Choose network location", 0, 400, 200, 120, $CBS_DROPDOWNLIST) ; Network location
GUICtrlSetData ($combo[1], "Firewall|Non-Firewall", "Choose network location")

$combo[2] = GUICtrlCreateCombo("Choose production status", 0, 425, 200, 120, $CBS_DROPDOWNLIST) ; Network location
GUICtrlSetData ($combo[2], "Production|Non-Production", "Choose production status")

$combo[3] = GUICtrlCreateCombo("Choose domain location", 0, 450, 200, 120, $CBS_DROPDOWNLIST) ; Network location
GUICtrlSetData ($combo[3], "Domain|Workgroup", "Choose domain location")

$hVal = GUICtrlCreateLabel ("Value: 0", 2, 2, 100, 20)

GUISetState ()

While 1
    Switch GUIGetMsg ()
        Case -3
            Exit
        Case $combo[1] To $combo[3]
            $combovaltotal = 0
            For $i = 1 To 3
                $combovaltotal += _GUICtrlComboBox_GetCurSel (GUICtrlGetHandle ($combo[$i])) * 2^($i - 2 + $i)
            Next
            GUICtrlSetData ($hVal, "Value: " & $combovaltotal)
    EndSwitch
WEnd

Mat

Link to comment
Share on other sites

That's some nifty stuff, Mat, thanks!

Now I guess this should come easy, but I want to force one of the combo boxes to be a certain option.

$combo1 = GUICtrlCreateCombo("Choose Network Location", 0, 400, 200, 120) ; create first item
GUICtrlSetData($combo1, "Firewall|Non-Firewall", "") ; add other item snd set a new default
$combo2 = GUICtrlCreateCombo("Choose Production Status", 0, 425, 200, 120) ; create first item
GUICtrlSetData($combo2, "Production|Non-Production", "") ; add other item snd set a new default
$combo3 = GUICtrlCreateCombo("Choose Domain Location", 0, 450, 200, 120) ; create first item
GUICtrlSetData($combo3, "Domain|Workgroup", "") ; add other item snd set a new default

Func button1()
   _GUICtrlComboBoxEx_SetCurSel($combo3, "Workgroup")
EndFunc

Wrong function?

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...