Sign in to follow this  
Followers 0
PantZ4

Pick selection in a combo box?

9 posts in this topic

Alright I need to pick something out of a combo box and so far I have figured out to drop the combo box down, but I can't see anything about selection a option.

I can see a WinMenuSelectItem but of what I can read it only works for file menu.

Thanks in advance.

Share this post


Link to post
Share on other sites



Alright I need to pick something out of a combo box and so far I have figured out to drop the combo box down, but I can't see anything about selection a option.

I can see a WinMenuSelectItem but of what I can read it only works for file menu.

Thanks in advance.

ControlCommand

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Alright I need to pick something out of a combo box and so far I have figured out to drop the combo box down, but I can't see anything about selection a option.

I can see a WinMenuSelectItem but of what I can read it only works for file menu.

Thanks in advance.

ControlCommand()

ControlSetText()


Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

or look at combobox udfs and ControlGetHandle in the latest beta

Edited by GaryFrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Total missed SetCurrentSelection <.<

Thanks.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Alright I need to pick something out of a combo box and so far I have figured out to drop the combo box down, but I can't see anything about selection a option.

I can see a WinMenuSelectItem but of what I can read it only works for file menu.

Thanks in advance.

#include <GUIConstants.au3>
GUICreate("My GUI combo")  
$combx = GUICtrlCreateCombo ("", 10,10) 
$data = "item1|item2|item3"
GUICtrlSetData($combx,$data,"item3") 
$Button1 = GUICtrlCreateButton ( "SelectString item1",  250, 50 ,100,30)
$Button2 = GUICtrlCreateButton ( "SelectString item2",  250, 90 ,100,30)
$Button3 = GUICtrlCreateButton ( "SelectString item3",  250, 130 ,100,30)
GUISetState ()


While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $combx
MsgBox(0, "", "ControlCommand-SelectString ===> " & GUICtrlRead($combx) , 3)
        Case $msg = $Button1
$var = ControlGetText("My GUI combo", "", $combx)
ControlFocus("My GUI combo",$var, $combx)
ControlCommand ( "My GUI combo", $var, $combx, "SelectString" , "item1")
        Case $msg = $Button2
$var = ControlGetText("My GUI combo", "", $combx)
ControlFocus("My GUI combo",$var, $combx)
ControlCommand ( "My GUI combo", $var, $combx, "SelectString" , "item2")
        
        Case $msg = $Button3
$var = ControlGetText("My GUI combo", "", $combx)
ControlFocus("My GUI combo",$var, $combx)
ControlCommand ( "My GUI combo", $var, $combx, "SelectString" , "item3")
    EndSelect
Wend
Edited by wolf9228

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites

or

#include <GUIConstants.au3>
GUICreate("My GUI combo")  
$combx = GUICtrlCreateCombo ("", 10,10) 
$data = "item1|item2|item3"
GUICtrlSetData($combx,$data,"item3") 
$Button1 = GUICtrlCreateButton ( "SelectString item1",  250, 50 ,100,30)
$Button2 = GUICtrlCreateButton ( "SelectString item2",  250, 90 ,100,30)
$Button3 = GUICtrlCreateButton ( "SelectString item3",  250, 130 ,100,30)
GUISetState ()


While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $combx
MsgBox(0, "", "SelectString ===> " & GUICtrlRead($combx) , 3)
        Case $msg = $Button1
$var = ControlGetText("My GUI combo", "", $combx)
ControlFocus("My GUI combo",$var, $combx)
GUICtrlSetData($combx,$data,"item1")
        Case $msg = $Button2
$var = ControlGetText("My GUI combo", "", $combx)
ControlFocus("My GUI combo",$var, $combx)
GUICtrlSetData($combx,$data,"item2")
        
        Case $msg = $Button3
$var = ControlGetText("My GUI combo", "", $combx)
ControlFocus("My GUI combo",$var, $combx)
GUICtrlSetData($combx,$data,"item3")
    EndSelect
Wend

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

beta

#include <GuiConstants.au3>
#include <GUIComboBox.au3>

Opt('MustDeclareVars', 1)

$Debug_CB = False ; Check ClassName being passed to ComboBox/ComboBoxEx functions, set to True and use a handle to another control to see it work

Global $hCombo

Example_Internal()
Example_External()

Func Example_Internal()
    Local $hGUI

    ; Create GUI
    $hGUI = GUICreate("(Internal) ComboBox Get Cur Sel", 400, 296)
    $hCombo = GUICtrlCreateCombo("", 2, 2, 396, 296)
    GUISetState()

    ; Add files
    _GUICtrlComboBox_BeginUpdate ($hCombo)
    _GUICtrlComboBox_AddDir ($hCombo, @WindowsDir & "\*.exe")
    _GUICtrlComboBox_EndUpdate ($hCombo)

    ; Select Item
    _GUICtrlComboBox_SetCurSel ($hCombo, 2)
    
    ; Get Cur Sel
    MsgBox(4160, "Information", "Cur Sel: " & _GUICtrlComboBox_GetCurSel ($hCombo))

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example_Internal

Func Example_External()
    Local $hGUI

    ; Create GUI
    $hGUI = GUICreate("(External) ComboBox Get Cur Sel", 400, 296)
    $hCombo = _GUICtrlComboBox_Create ($hGUI, "", 2, 2, 396, 296)
    GUISetState()

    ; Add files
    _GUICtrlComboBox_BeginUpdate ($hCombo)
    _GUICtrlComboBox_AddDir ($hCombo, @WindowsDir & "\*.exe")
    _GUICtrlComboBox_EndUpdate ($hCombo)

    ; Select Item
    _GUICtrlComboBox_SetCurSel ($hCombo, 2)
    
    ; Get Cur Sel
    MsgBox(4160, "Information", "Cur Sel: " & _GUICtrlComboBox_GetCurSel ($hCombo))

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example_External

look up _GUICtrlComboBox_GetLBText to get the text of any item by index

Edited by GaryFrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

beta with icons

#include <GuiConstants.au3>
#include <GuiComboBoxEx.au3>
#include <GuiImageList.au3>

Opt('MustDeclareVars', 1)

$Debug_CB = False ; Check ClassName being passed to ComboBox/ComboBoxEx functions, set to True and use a handle to another control to see it work

Global $hCombo

_Main()

Func _Main()
    Local $hGUI, $hImage
    
    ; Create GUI
    $hGUI = GUICreate("ComboBoxEx Get Cur Sel", 400, 300)
    $hCombo = _GUICtrlComboBoxEx_Create ($hGUI, "", 2, 2, 394, 100, BitOR($CBS_SIMPLE, $WS_VSCROLL, $WS_BORDER))
    GUISetState()

    $hImage = _GUIImageList_Create (16, 16, 5, 3)
    _GUIImageList_AddIcon ($hImage, @SystemDir & "\shell32.dll", 110)
    _GUIImageList_AddIcon ($hImage, @SystemDir & "\shell32.dll", 131)
    _GUIImageList_AddIcon ($hImage, @SystemDir & "\shell32.dll", 165)
    _GUIImageList_AddIcon ($hImage, @SystemDir & "\shell32.dll", 168)
    _GUIImageList_AddIcon ($hImage, @SystemDir & "\shell32.dll", 137)
    _GUIImageList_AddIcon ($hImage, @SystemDir & "\shell32.dll", 146)
    _GUIImageList_Add ($hImage, _GUICtrlComboBoxEx_CreateSolidBitMap ($hCombo, 0xFF0000, 16, 16))
    _GUIImageList_Add ($hImage, _GUICtrlComboBoxEx_CreateSolidBitMap ($hCombo, 0x00FF00, 16, 16))
    _GUIImageList_Add ($hImage, _GUICtrlComboBoxEx_CreateSolidBitMap ($hCombo, 0x0000FF, 16, 16))
    _GUICtrlComboBoxEx_SetImageList ($hCombo, $hImage)

    _GUICtrlComboBoxEx_InitStorage ($hCombo, 150, 300)
    
    _GUICtrlComboBoxEx_BeginUpdate ($hCombo)
    For $x = 0 To 149
        _GUICtrlComboBoxEx_AddString ($hCombo, StringFormat("%03d : Random string", Random(1, 100, 1)), Random(0, 8, 1), Random(0, 8, 1), Random(0, 8, 1))
    Next
    _GUICtrlComboBoxEx_EndUpdate ($hCombo)

    ; Set Cur Sel
    _GUICtrlComboBoxEx_SetCurSel ($hCombo, Random(0, 149, 1))
    
    ; Get Cur Sel
    MsgBox(4160, "Information", "Current Sel: " & _GUICtrlComboBoxEx_GetCurSel ($hCombo))

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>_Main

look up _GUICtrlComboBoxEx_GetItemText to get text of any given index


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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  
Followers 0