Jump to content

Setting Selected Data back to "" or Nothing in ComboBox


Grax
 Share

Recommended Posts

Ok I have a ComboBox that is a Drop Down List.

If the user selects an invalid selection, I pop-up a msgbox and display an error and then set focus back on the ComboBox. The displayed item is still the invalid selection the user selected. This would be fine if the user couldn't go onto another input until the error was corrected. However the user can click elsewhere or tab to the next input without seeing the error again.

So how to I set the Drop Down List back to it's default of nothing selected? I'd rather delete the input and then recreate it. Any other suggestions?

I guess along these same lines. How do I allow a user to set the selection of a drop down list back to nothing? The input isn't required and should they change their mind about inputing it I want them to be able to select nothing.

Thanks,

Andrew

Link to comment
Share on other sites

Create an item whose text is just a space in the first slot, like so, when you are making your list.

#include <GUIConstants.au3>
#include <GuiComboBoxEx.au3>

$Form1 = GUICreate("Form1", 186, 55, 193, 125)
$Combo1 = GUICtrlCreateCombo("", 16, 16, 145, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
$ComboData = " |1|2|3|4|5|6"
GUICtrlSetData(-1, $ComboData,0)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Combo1
            Selectionchanged(GUICtrlRead ($Combo1))
        EndSwitch
        
WEnd

Func Selectionchanged($ListOption)

    MsgBox(0, "You chose item:" & $ListOption , "Now resetting to index[0] (the first position)")
    _GUICtrlComboBox_SetCurSel($Combo1, 0)
EndFunc

In order to access the control(easily, at least,) you'll need to include <GuiComboBoxEx.au3>

This will let you use the following functions to access and set the currently selected item.

_GUICtrlComboBoxEx_GetCurSel

_GUICtrlComboBoxEx_SetCurSel

The validation is all up to you :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...