Sign in to follow this  
Followers 0
drw4281

Set position of combo box

6 posts in this topic

Hey guys,

So, I have a combo box with a list of items. I want the user to be able to select an item via the combo box like normal, but also be able to use PREV and NEXT buttons I have to walk up and down the list. I can't figure out how to set the selected item in a combo box though. Thanks.

Share this post


Link to post
Share on other sites



drw4281,

Do you mean like this: :oops:

#include <GUIConstantsEx.au3>
#include <GuiComboBox.au3>
#include <Array.au3>

$hGUI = GUICreate("Test", 500, 500)

$hCombo = GUICtrlCreateCombo("", 10, 10, 200, 20)

$sData = ""
For $i = 1 To 20
    $sData &= "|" & "Item " & $i
Next
GUICtrlSetData($hCombo, $sData)

$hButton_Up = GUICtrlCreateButton("Up", 250, 10, 80, 30)
$hButton_Dn = GUICtrlCreateButton("Down", 250, 50, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton_Up
            $sCurr = GUICtrlRead($hCombo)
            $aList = _GUICtrlComboBox_GetListArray($hCombo)
            $iIndex = _ArraySearch($aList, $sCurr)
            If $iIndex > 1 Then
                _GUICtrlComboBox_SetEditText($hCombo, $aList[$iIndex - 1])
            EndIf
        Case $hButton_Dn
            $sCurr = GUICtrlRead($hCombo)
            $aList = _GUICtrlComboBox_GetListArray($hCombo)
            $iIndex = _ArraySearch($aList, $sCurr)
            If $iIndex < $aList[0] Then
                _GUICtrlComboBox_SetEditText($hCombo, $aList[$iIndex + 1])
            EndIf
    EndSwitch

WEnd

Any use? :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Or this one:

#include "ComboConstants.au3"
GUICreate("Test")
Global $nCombo = GUICtrlCreateCombo("", 10, 10, 100, 60, 0x3)
GUICtrlSetData(-1, "Item1|Item2|Item3|Item4", "Item1")
Global $nUP = GUICtrlCreateButton("t", 110, 9, 20, 12)
GUICtrlSetFont(-1, 10, 400, 0, "Marlett")
Global $nDOWN = GUICtrlCreateButton("u", 110, 20, 20, 12)
GUICtrlSetFont(-1, 10, 400, 0, "Marlett")
GUISetState()
Global $msg
Do
 $msg = GUIGetMsg()
 If $msg = $nUP Then GUICtrlSendMsg($nCombo, $CB_SETCURSEL, GUICtrlSendMsg($nCombo, $CB_GETCURSEL, 0, 0) + 1, 0)
 If $msg = $nDOWN Then GUICtrlSendMsg($nCombo, $CB_SETCURSEL, GUICtrlSendMsg($nCombo, $CB_GETCURSEL, 0, 0) - 1, 0)
Until $msg = -3

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Case $hButton_Up
            $sCurr = GUICtrlRead($hCombo)
            $aList = _GUICtrlComboBox_GetListArray($hCombo)
            $iIndex = _ArraySearch($aList, $sCurr)
            If $iIndex > 1 Then
                _GUICtrlComboBox_SetEditText($hCombo, $aList[$iIndex - 1])
            EndIf
        Case $hButton_Dn
            $sCurr = GUICtrlRead($hCombo)
            $aList = _GUICtrlComboBox_GetListArray($hCombo)
            $iIndex = _ArraySearch($aList, $sCurr)
            If $iIndex < $aList[0] Then
                _GUICtrlComboBox_SetEditText($hCombo, $aList[$iIndex + 1])
            EndIf

Just simplified by my recomended way:

Case $hButton_Up
            $iIndex = _GUICtrlComboBox_GetCurSel($hCombo)
            _GUICtrlComboBox_SetCurSel($hCombo, $iIndex - 1)
Case $hButton_Dn
            $iIndex = _GUICtrlComboBox_GetCurSel($hCombo)
            _GUICtrlComboBox_SetCurSel($hCombo, $iIndex + 1)

Note: There is no error/bound checking

Edited by Zedna

Share this post


Link to post
Share on other sites

Awesome, thanks guys. Now to just decide which approach to use, haha.

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