AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[SOLVED] Deselect ListBox that is not multi-select

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
ghee22



Joined: 04 Jul 2009
Posts: 36

PostPosted: Tue Oct 20, 2009 7:14 pm    Post subject: [SOLVED] Deselect ListBox that is not multi-select Reply with quote

The following from GuiControl does not work:
Code:
PostMessage, 0x185, 0, -1, ListBox1  ; Deselect all items.


The ListBox is not multi-select.

Solution:
Thanks to all involved.
jaco0646 wrote:
You may use the window handle (HWND) of each listbox.
Code:
Gui, Add, ListBox, AltSubmit HWNDbox_1 , No|Yes
Gui, Add, ListBox, r4 AltSubmit HWNDcrq_impact , 1-Major|2-Significant|3-Minor|4-Standard
Gui, Add, Button, , Test
Gui, Show, , Test listbox unselect
return
GuiClose:
 ExitApp

ButtonTest:
   PostMessage, 0x186, -1, 0,,ahk_id %box_1%
   PostMessage, 0x186, -1, 0,,ahk_id %crq_impact%
   Gui,Submit,NoHide
   Return


Last edited by ghee22 on Sat Nov 07, 2009 2:10 pm; edited 3 times in total
Back to top
View user's profile Send private message
txquestor



Joined: 22 Aug 2009
Posts: 294

PostPosted: Tue Oct 20, 2009 7:29 pm    Post subject: Reply with quote

Here is a simpler method.
Code:

Gui, Show
SendInput {PgUp}   ; deselects a control when the text is highlighted after creating and showing it

_________________

"Man's quest for knowledge is an expanding series whose limit is infinity"
Back to top
View user's profile Send private message
ghee22



Joined: 04 Jul 2009
Posts: 36

PostPosted: Tue Oct 20, 2009 7:39 pm    Post subject: Reply with quote

txquestor wrote:
Here is a simpler method.
Code:

Gui, Show
SendInput {PgUp}   ; deselects a control when the text is highlighted after creating and showing it


This does not deselect all items. This selects the first item. How can I select no items?
Back to top
View user's profile Send private message
jaco0646



Joined: 07 Oct 2006
Posts: 3113
Location: MN, USA

PostPosted: Tue Oct 20, 2009 7:52 pm    Post subject: Re: Deselect ListBox that is not multi-select Reply with quote

The message for single-selection list boxes is different.
Code:
PostMessage, 0x186, -1, 0, ListBox1  ; Deselect item.
Back to top
View user's profile Send private message Visit poster's website
ghee22



Joined: 04 Jul 2009
Posts: 36

PostPosted: Fri Oct 30, 2009 9:40 pm    Post subject: Re: Deselect ListBox that is not multi-select Reply with quote

jaco0646 wrote:
The message for single-selection list boxes is different.
Code:
PostMessage, 0x186, -1, 0, ListBox1  ; Deselect item.


This did not work for me. Here's my example code:
Code:
Gui, Add, ListBox, vlistbox1 , No|Yes
Gui, Add, Button, , Test
Gui, Show, , Test listbox unselect

ButtonTest:
   PostMessage, 0x186, -1, 0,,listbox1
   Gui,Submit,NoHide
   Return
Back to top
View user's profile Send private message
jaco0646



Joined: 07 Oct 2006
Posts: 3113
Location: MN, USA

PostPosted: Fri Oct 30, 2009 10:51 pm    Post subject: Reply with quote

You added a comma.
Back to top
View user's profile Send private message Visit poster's website
ghee22



Joined: 04 Jul 2009
Posts: 36

PostPosted: Sat Oct 31, 2009 5:37 pm    Post subject: Reply with quote

jaco0646 wrote:
You added a comma.


You are correct! Without the repeat comma at the end, the code works:
Code:
Gui, Add, ListBox, AltSubmit vlistbox1 , No|Yes
Gui, Add, Button, , Test
Gui, Show, , Test listbox unselect

ButtonTest:
   PostMessage, 0x186, -1, 0,listbox1
   Gui,Submit,NoHide
   Return
Back to top
View user's profile Send private message
ghee22



Joined: 04 Jul 2009
Posts: 36

PostPosted: Tue Nov 03, 2009 3:10 pm    Post subject: Reply with quote

How can one use the PostMessage command to work with the listbox's associated variable name?

I could only get the PostMessage command to work with listbox# where '#' is the number of which the listbox was added (listbox1 for the first listbox added, listbox2 for the second, and so on).

To exemplify, here are three different scenarios:

Scenario 1:
Both listboxes will clear.
Code:
Gui, Add, ListBox, AltSubmit vbox_1 , No|Yes
Gui, Add, ListBox, r4 AltSubmit vcrq_impact , 1-Major|2-Significant|3-Minor|4-Standard
Gui, Add, Button, , Test
Gui, Show, , Test listbox unselect

ButtonTest:
   PostMessage, 0x186, -1, 0, listbox1
   PostMessage, 0x186, -1, 0, listbox2
   Gui,Submit,NoHide
   Return


Scenario 2:
Only the second listbox will clear.
Code:
Gui, Add, ListBox, AltSubmit vbox_1 , No|Yes
Gui, Add, ListBox, r4 AltSubmit vcrq_impact , 1-Major|2-Significant|3-Minor|4-Standard
Gui, Add, Button, , Test
Gui, Show, , Test listbox unselect

ButtonTest:
   PostMessage, 0x186, -1, 0, box_1
   PostMessage, 0x186, -1, 0, listbox2
   Gui,Submit,NoHide
   Return


Scenario 3:
No listboxes will clear
Code:
Gui, Add, ListBox, AltSubmit vbox_1 , No|Yes
Gui, Add, ListBox, r4 AltSubmit vcrq_impact , 1-Major|2-Significant|3-Minor|4-Standard
Gui, Add, Button, , Test
Gui, Show, , Test listbox unselect

ButtonTest:
   PostMessage, 0x186, -1, 0, box_1
   PostMessage, 0x186, -1, 0, crq_impact
   Gui,Submit,NoHide
   Return
Back to top
View user's profile Send private message
jaco0646



Joined: 07 Oct 2006
Posts: 3113
Location: MN, USA

PostPosted: Tue Nov 03, 2009 3:21 pm    Post subject: Reply with quote

You may use the window handle (HWND) of each listbox.
Code:
Gui, Add, ListBox, AltSubmit HWNDbox_1 , No|Yes
Gui, Add, ListBox, r4 AltSubmit HWNDcrq_impact , 1-Major|2-Significant|3-Minor|4-Standard
Gui, Add, Button, , Test
Gui, Show, , Test listbox unselect
return
GuiClose:
 ExitApp

ButtonTest:
   PostMessage, 0x186, -1, 0,,ahk_id %box_1%
   PostMessage, 0x186, -1, 0,,ahk_id %crq_impact%
   Gui,Submit,NoHide
   Return
Back to top
View user's profile Send private message Visit poster's website
ghee22



Joined: 04 Jul 2009
Posts: 36

PostPosted: Tue Nov 03, 2009 10:45 pm    Post subject: Reply with quote

jaco0646 wrote:
You may use the window handle (HWND) of each listbox.
Code:
Gui, Add, ListBox, AltSubmit HWNDbox_1 , No|Yes
Gui, Add, ListBox, r4 AltSubmit HWNDcrq_impact , 1-Major|2-Significant|3-Minor|4-Standard
Gui, Add, Button, , Test
Gui, Show, , Test listbox unselect
return
GuiClose:
 ExitApp

ButtonTest:
   PostMessage, 0x186, -1, 0,,ahk_id %box_1%
   PostMessage, 0x186, -1, 0,,ahk_id %crq_impact%
   Gui,Submit,NoHide
   Return


Thank you. This works and is the best solution.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group