clear dropdown field

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
DataLife
Posts: 447
Joined: 29 Sep 2013, 19:52

clear dropdown field

09 Oct 2017, 17:01

After selecting an item in the dropdown list, I need to click a button and clear the selected item. It is called the Edit Field on a combobox. I don't need to clear the items in the dropdown list only clear what is visable in the dropdown list (non-editable) box.

Code: Select all

Gui, add, dropdownlist,,item1|item2|item3
Gui, add, button,gclear,Clear selected Dropdown item
gui, show, autosize
return


clear:
GuiControl,text,combobox1
return
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: clear dropdown field

09 Oct 2017, 17:59

Hi DataLife,

Use Control, Delete:

Code: Select all

Gui, Add, DDL, vDDL hwndDDL_ID +AltSubmit, item1|item2|item3 ;  if the control has the AltSubmit property, the output variable will receive the item's position number
Gui, Add, Button, gClear, &Clear selected Dropdown item
Gui, Show, Autosize
return


clear:
GuiControlGet, DDL ; retieve the item's position number
Control, Delete, %DDL%,, % "ahk_id " . DDL_ID ; to operate upon a control's HWND (window handle), leave the Control parameter blank and specify ahk_id %ControlHwnd% for the WinTitle parameter 
return
my scripts
User avatar
DataLife
Posts: 447
Joined: 29 Sep 2013, 19:52

Re: clear dropdown field

09 Oct 2017, 19:13

A_AhkUser wrote:Hi DataLife,

Use Control, Delete:

Code: Select all

Gui, Add, DDL, vDDL hwndDDL_ID +AltSubmit, item1|item2|item3 ;  if the control has the AltSubmit property, the output variable will receive the item's position number
Gui, Add, Button, gClear, &Clear selected Dropdown item
Gui, Show, Autosize
return


clear:
GuiControlGet, DDL ; retieve the item's position number
Control, Delete, %DDL%,, % "ahk_id " . DDL_ID ; to operate upon a control's HWND (window handle), leave the Control parameter blank and specify ahk_id %ControlHwnd% for the WinTitle parameter 
return
I don't want to delete the item from the dropdown list. I only want to clear it from the "dropdown field".
Here is step by step what I want.

1. Create a dropdownlist with 3 items.
2. Show it with a GUI.
3. Select anyone of the 3 items. That item shows up on the "dropdown field"
4. I will operate on that item at some point in my script. After I operate on that item I want to clear that item from the "dropdown field". I do not want to delete it from the dropdown list.
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
User avatar
DataLife
Posts: 447
Joined: 29 Sep 2013, 19:52

Re: clear dropdown field

09 Oct 2017, 19:20

I finally found the solution here.
https://autohotkey.com/board/topic/2128 ... ntry139519

I give the dropdownlist a hwnd ID, then use

Code: Select all

SendMessage, 0x014E, -1, 0,, ahk_id %DDL_ID%
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: clear dropdown field

09 Oct 2017, 20:01

Interesting, thanks for sharing.

CB_SETCURSEL := 0x14E

CB_SETCURSEL message (Windows)
https://msdn.microsoft.com/en-us/librar ... s.85).aspx
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
just me
Posts: 9458
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: clear dropdown field

10 Oct 2017, 01:59

Code: Select all

Gui, Add, DDL, vMyDDL, item1|item2|item3
Gui, Add, button, gClear, Clear selected Dropdown item
Gui, Show, w400 h300, Test
Return

GuiClose:
ExitApp

Clear:
GuiControl, Choose , MyDDL, 0
Return
GuiControl wrote:GuiControl, Choose, ControlID, N: Sets the selection in a ListBox, DropDownList, ComboBox, or Tab control to be the Nth entry. N should be 1 for the first entry, 2 for the second, etc. If N is not an integer, the ChooseString method described below will be used instead. [v1.1.06+]: If N is zero, the ListBox, DropDownList or ComboBox's current selection is removed.
User avatar
DataLife
Posts: 447
Joined: 29 Sep 2013, 19:52

Re: clear dropdown field

10 Oct 2017, 12:51

just me wrote:

Code: Select all

Gui, Add, DDL, vMyDDL, item1|item2|item3
Gui, Add, button, gClear, Clear selected Dropdown item
Gui, Show, w400 h300, Test
Return

GuiClose:
ExitApp

Clear:
GuiControl, Choose , MyDDL, 0
Return
GuiControl wrote:GuiControl, Choose, ControlID, N: Sets the selection in a ListBox, DropDownList, ComboBox, or Tab control to be the Nth entry. N should be 1 for the first entry, 2 for the second, etc. If N is not an integer, the ChooseString method described below will be used instead. [v1.1.06+]: If N is zero, the ListBox, DropDownList or ComboBox's current selection is removed.
Of course it was right there in front of me. I read so much that if I felt I was going down the wrong path I would quit reading. That is why I missed "If N is zero, the ListBox, DropDownList or ComboBox's current selection is removed."

thanks
DataLife
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen, mikeyww and 396 guests