Tankbuster Posted December 19, 2013 Share Posted December 19, 2013 Hello, I wonder if there is an existing solution (may aold post I overlooked?) that handles "partial combobox match set as default" ? Eg: A dynamic filled combobox contains items like (3 items) item-1-a item-2-a item-3-a And now I want to set a item as default by not knowing exactly the item text. As an example I need to set the item "item-2" as the default. With the build in I need to know the exact string right? So here GUICtrlSetData(-1, "item-1-a|item-2-a|item-3-a","item-2-a") But I need something like GUICtrlSetData(-1, "item-1-a|item-2-a|item-3-a","item-2*") (the asterix on the ned indicates "any chars". The combo is created with the build in method GUICtrlCreateCombo if this is important not by the _udf My current idea is to build a function that loops over all items and do a partial compare and returns than the index. But before creating this, I want to know if this has been done before. Re-inventing the wheel does not make much sense. #include <GUIConstantsEx.au3> Example() Func Example() Local $msg GUICreate("My GUI") ; will create a dialog box that when displayed is centered GUICtrlCreateCombo("", 10, 10) GUICtrlSetData(-1, "item-1-a|item-2-a|item-3-a","item-2-a") GUISetState() ; will display an empty dialog box with a combo control with focus on ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd EndFunc ;==>Example Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted December 19, 2013 Moderators Solution Share Posted December 19, 2013 Tankbuster,I would do it like this:expandcollapse popup#include <GUIConstantsEx.au3> #include <Array.au3> Example() Func Example() Local $msg ; Put combo items into an array Local $aCombo_Data[3] = ["item-1-a", "item-2-a", "item-3-a"] Local $sMatch = "item-1" ; Look for a partial match Local $sDefault Local $iIndex = _ArraySearch($aCombo_Data, $sMatch, 0, 0, 0, 1) ; Do partial search ; Set a default If @error Then $sDefault = "" Else $sDefault = $aCombo_Data[$iIndex] EndIf ; Get the data into a form to insert Local $sCombo_Data = _ArrayToString($aCombo_Data, "|") GUICreate("My GUI") ; will create a dialog box that when displayed is centered GUICtrlCreateCombo("", 10, 10) GUICtrlSetData(-1, $sCombo_Data, $sDefault) GUISetState() ; will display an empty dialog box with a combo control with focus on ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd EndFunc ;==>ExampleSeems to work when I test it. 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 Link to comment Share on other sites More sharing options...
Tankbuster Posted December 19, 2013 Author Share Posted December 19, 2013 (edited) Hey I knew it, it must be that easy (....if you are Melba ) Thx. Much better than "looping". Nice _Arraysearch. Next time I expect you to be even faster (post the solution before my question .......) //edit: I just found the "Mark solved" button, nice never saw that before.... Edited December 19, 2013 by Tankbuster Link to comment Share on other sites More sharing options...
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