Jump to content
wysocki

How can I clear a combobox $CBS_DROPDOWNLIST

Recommended Posts

wysocki

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?

Share this post


Link to post
Share on other sites
Deye

Look for _GUICtrlComboBox_DeleteString Or GUICtrlComboBox_ResetContent

Edited by Deye

Share this post


Link to post
Share on other sites
TheSaint

You can also just set blank strings.

GUICtrlSetData($Combo_xx, "", "")


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

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)

userbar.png

Share this post


Link to post
Share on other sites
wysocki

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?

Share this post


Link to post
Share on other sites
Zedna

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.

Share this post


Link to post
Share on other sites
wysocki
#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!)

Share this post


Link to post
Share on other sites
TheXman

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 by TheXman

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

×