shornw Posted July 16, 2010 Share Posted July 16, 2010 Hi all Is it possible to set up a combi box so that as the user types it selects from the choices in a list, so for example, GUICreate("Options available", 200, 80) ; will create a dialog box that when displayed is centered GUICtrlCreateLabel("Please select from the drop-down box", 10, 10) $cList = GUICtrlCreateCombo("User Selection", 20, 40, 80,20) GUICtrlSetData(-1, "Apple|Banana|Cherry|Damson|Other", "Apple") if the user typed 'B', Banana would be higlighted. I dont really want users to be able to type free text. Sorry if this is something obvious, but I've looked theough the help files and now Im even more confused Thanks for looking, any assistance greatly appreciated. [font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font] Link to comment Share on other sites More sharing options...
jfcby Posted July 16, 2010 Share Posted July 16, 2010 Try this... #include <GUIConstantsEx.au3> #include <ComboConstants.au3> Opt('MustDeclareVars', 1) Global $cList Example() Func Example() Local $msg GUICreate("My GUI combo", 200, 80) ; will create a dialog box that when displayed is centered GUICtrlCreateLabel("Please select from the drop-down box", 10, 10) $cList = GUICtrlCreateCombo("User Selection", 20, 40, 80, 20, $CBS_DROPDOWNLIST) GUICtrlSetData(-1, "Apple|Banana|Cherry|Damson|Other", "Apple") GUISetState() ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd EndFunc ;==>Example jfcby Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB **** Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 16, 2010 Moderators Share Posted July 16, 2010 shornw,There is a _GUICtrlComboBox_AutoComplete function - you have to open the combo and then start typing before the autocompletion begins. Here is a short demo: #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiComboBox.au3> $hGUI = GUICreate("AutoComplete Combo Demo", 300, 200) $hCombo = GUICtrlCreateCombo("", 70, 75, 170, 20, $CBS_DROPDOWNLIST) ; the style makes the combo read-only GUICtrlSetData(-1, "Apple|Banana|Cherry|Damson|Other", "Apple") GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam) Local $iIDFrom = BitAND($wParam, 0x0000FFFF) Local $iCode = BitShift($wParam, 16) Switch $iIDFrom Case $hCombo Switch $iCode Case $CBN_EDITCHANGE _GUICtrlComboBox_AutoComplete($hCombo) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMANDI also wrote this a while ago and it might perhaps be of interest. You start typing in the input box and the valid items in the data appear in the list below - clicking an item in the list puts it in the edit box. If no items match the typing, then no list is displayed. Pressing the button checks that a valid data item is in the input and shows a MsgBox. The data is a random list of 5 letter combinations at present, but that is not difficult to change:expandcollapse popup#include <GUIConstantsEx.au3> #include <Array.au3> Global $hGUI, $hInput, $hList, $sPartialData, $asKeyWords[100] Keywords() $hGUI = GUICreate("Example", 200, 400) $hInput = GUICtrlCreateInput("", 5, 5, 190, 20) $hList = GUICtrlCreateList("", 5, 30, 190, 325, BitOR(0x00100000, 0x00200000)) $hButton = GUICtrlCreateButton("Read", 60, 360, 80, 30) GUISetState(@SW_SHOW, $hGUI) $sCurr_Input = "" While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hList $sChosen = GUICtrlRead($hList) If $sChosen <> "" Then GUICtrlSetData($hInput, $sChosen) Case $hButton If $sPartialData <> "" Then $sFinal = GUICtrlRead($hInput) If _ArraySearch($asKeyWords, $sFinal) > 0 Then MsgBox(0, "Chosen", $sFinal) EndIf EndIf EndSwitch ; If input has changed, refill list with matching items If GUICtrlRead($hInput) <> $sCurr_Input Then CheckInputText() $sCurr_Input = GUICtrlRead($hInput) EndIf WEnd Func Keywords() Local $sData For $i = 0 To 99 $asKeyWords[$i] = Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) $sData &= $asKeyWords[$i] & "|" Next GUICtrlSetData($hList, $sData) EndFunc ;==>Keywords Func CheckInputText() $l = StringLen(GUICtrlRead($hInput)) $sPartialData = "|" ; Start with delimiter so new data always replaces old Local $sInput = GUICtrlRead($hInput) If $sInput <> "" Then For $i = 0 To 99 If StringLeft($asKeyWords[$i], $l) = $sInput Then $sPartialData &= $asKeyWords[$i] & "|" Next GUICtrlSetData($hList, $sPartialData) EndIf EndFunc ;==>CheckInputTextIf you are interested in this second option, let me know what (if anything ) needs changing. 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...
shornw Posted July 16, 2010 Author Share Posted July 16, 2010 Thanks for this. Melba - I'll play around with it and see if I can make it work for me, Thanks for the code. Does anyone know if there is a maximum number of items that can be used in a ComboBox. I have a large dept list, so I have pointed the GUICtrlSetData at a document: $deplist = FileRead("C:\deplist.txt", 300) GuiCtrlSetData($deplist, "Please Select") but only 132 items appear. Thanks again [font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 16, 2010 Moderators Share Posted July 16, 2010 (edited) shornw,Read the Help file - the second parameter for FileRead is "the number of characters to read". So you are unlikely to read the whole list with just 300 chars. Use FileRead("C:\deplist.txt") and then you get the whole file. I assume you store the delimiters in the file? M23Edit: Added the delimiter part. Edited July 16, 2010 by Melba23 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...
shornw Posted July 16, 2010 Author Share Posted July 16, 2010 Right as usual Melba [sigh] Now I have a new issue. If I include the $CBS_DROPDOWNLIST, I dont get a scrollbar and only a few items are listed. Any ideas, can I use multiple style items? How difficult is it to use your code to read a text file? Thanks [font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 16, 2010 Moderators Share Posted July 16, 2010 shornw,I bet you created your combo like this: $cList = GUICtrlCreateCombo("User Selection", 20, 40, 80, 20, $CBS_DROPDOWNLIST)Am I right? If so, then you have overwritten the default styles, which include a vertical scroll bar. Remember that if you define a style you overwrite any existing styles. So you have to restate all the existing styles that you want to retain. Look at this example:#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ComboConstants.au3> $sData = "" For $i = 1 To 100 $sData &= $i & "|" Next $hGUI = GUICreate("Test", 500, 500) $hCombo = GUICtrlCreateCombo("", 10, 10, 100, 20, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL, $WS_VSCROLL)) ; New style and old styles <<<<<<<<<<< GUICtrlSetData($hCombo, $sData) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEndAll clear? As to reading your file into my code, just replace function Keywords() with your file read code and it should work. 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...
shornw Posted July 16, 2010 Author Share Posted July 16, 2010 You are, of course, spot on. That was how I wrote the Combo, but in fairness it doesn't mention anywhere (obvious) in the help files....and I was on the right track with using multiple styles, so I'm not as embarrased as I might have been. Thank you so much for your assistance which is equalled only by your patience. As you may have guessed, I'm not a programmer but with your help I have a fully useable script. PS I'd never even heard of BITor LOL [font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 17, 2010 Moderators Share Posted July 17, 2010 shornw, Thank you so much for your assistanceMy pleasure. I'd never even heard of BITorTry looking here if you want to know more about it - and why you should use it to combine styles. 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...
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