drw4281 Posted November 25, 2011 Posted November 25, 2011 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.
Zedna Posted November 25, 2011 Posted November 25, 2011 (edited) Look at these functions in the helpfile #Include <GuiComboBox.au3> _GUICtrlComboBox_GetCurSel() _GUICtrlComboBox_SetCurSel() Edited November 25, 2011 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search
Moderators Melba23 Posted November 25, 2011 Moderators Posted November 25, 2011 drw4281, Do you mean like this: expandcollapse popup#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? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
funkey Posted November 25, 2011 Posted November 25, 2011 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 tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning.
Zedna Posted November 25, 2011 Posted November 25, 2011 (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 November 25, 2011 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search
drw4281 Posted November 25, 2011 Author Posted November 25, 2011 Awesome, thanks guys. Now to just decide which approach to use, haha.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now