wysocki Posted February 1, 2018 Posted February 1, 2018 I have a combobox that has a $CBS_DROPDOWNLIST style. Although the app starts with that control showing blank, after I select an item I'd like to clear it programmatically. I've tried the _GUICtrlComboBox_SetEditText() function but it states correctly that it will fail if the $CBS_DROPDOWNLIST style is used. Is there any way I can clear it back to initial state?
Deye Posted February 1, 2018 Posted February 1, 2018 (edited) Look for _GUICtrlComboBox_DeleteString Or GUICtrlComboBox_ResetContent Edited February 1, 2018 by Deye
TheSaint Posted February 1, 2018 Posted February 1, 2018 You can also just set blank strings. GUICtrlSetData($Combo_xx, "", "") Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)
wysocki Posted February 1, 2018 Author Posted February 1, 2018 Thanks, guys! But unfortunately, all those delete items from the control's dropdown data list. I just want to clear the currently selected data from the control (as it would appear on initialization) but still have the dropdown list remain intact. Any other ideas?
Zedna Posted February 2, 2018 Posted February 2, 2018 Simple reproducing script would be nice ... I think you should add also empty string when you are adding other values. Then you will not have problems with selecting this "empty string" from existing values. Resources UDF ResourcesEx UDF AutoIt Forum Search
wysocki Posted February 2, 2018 Author Posted February 2, 2018 #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiComboBox.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 338, 167, 192, 124) $Combo1 = GUICtrlCreateCombo("", 27, 22, 286, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL,$CBS_DROPDOWNLIST)) $Button1 = GUICtrlCreateButton("CLEAR", 132, 78, 79, 45) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUICtrlSetData($Combo1,'apple|banana|cherry|date') While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 ;GUICtrlSetData($Combo1,"") ;this just clears ALL the items in the box _GUICtrlComboBox_SetEditText($Combo1,'') ;this works but ONLY without style = $CBS_DROPDOWNLIST EndSwitch WEnd Ok, here's an example. Just select a value from the list then clicking the button should clear your selection (but leave the list intact). I don't want to include an empty string in the data because that should not be a valid value for the user to see/select. The _GUICtrlComboBox_SetEditText() works GREAT as long as I don't use the $CBS_DROPDOWNLIST style. I want to use that style because I'm running this on a small touchscreen and it's hard for the user to hit the dropdown button. This style allows them to click anywhere on the control to drop it down. (Another minor issue with $CBS_DROPDOWNLIST is that it actually does not allow you to click ANYWHERE on the control. The clickable area is related somewhat to the length of the text displayed!)
TheXman Posted February 2, 2018 Posted February 2, 2018 (edited) If I understand what you are trying to do, which is to just clear the selection, then the line below should do the job. Setting the index to -1 clears the selection. #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiComboBox.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 338, 167, 192, 124) $Combo1 = GUICtrlCreateCombo("", 27, 22, 286, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL,$CBS_DROPDOWNLIST)) $Button1 = GUICtrlCreateButton("CLEAR", 132, 78, 79, 45) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUICtrlSetData($Combo1,'apple|banana|cherry|date') While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 _GUICtrlComboBox_SetCurSel($Combo1, -1) EndSwitch WEnd Edited February 2, 2018 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
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