Toggle Gui Listbox Multi-Select Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Hellbent
Posts: 2114
Joined: 23 Sep 2017, 13:34

Toggle Gui Listbox Multi-Select

19 Nov 2023, 06:19

Does anyone know of a way to turn on and off the "Multi" option for listbox controls?
I have a functioning workaround but it would be nice to be able to just turn it on and off.

I would like for the second listbox ( bottom one ) in this example to be able to toggle multi select.

Code: Select all

#SingleInstance Force
Gui, Add, Listbox, w200 r6 Multi, Item|Item|Item|Item|Item|Item|Item|Item|
Gui, Add, Listbox, wp r6 hwndListboxHwnd , Item|Item|Item|Item|Item|Item|Item|Item|
Gui, Add, Checkbox, gToggleMultiSelect hwndCheckboxHwnd , Toggle Multi-Select
Gui, Show

return 

GuiClose:
GuiContextMenu:
*ESC::ExitApp

ToggleMultiSelect:	;{
	GuiControlGet, toggleState ,, % CheckboxHwnd
	if( toggleState ){
		;turn on multiSelect
		MsgBox, multi is On
	}else{
		;turn off multiSelect 
		MsgBox, multi is Off
	}
	return
;}
Thanks in advance.
Last edited by Hellbent on 19 Nov 2023, 07:50, edited 1 time in total.
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Toggle Gui Listbox Multi-Select  Topic is solved

19 Nov 2023, 07:47

Code: Select all

; This script enables or disables selection of multiple ListBox items.
#Requires AutoHotkey v1.1.33
Gui +AlwaysOnTop
Gui Font, s10
Gui Add, ListBox, w230 vsel Multi gCheck, A|B|C
Gui Add, Button , wp   Default, OK
Gosub F5 ; Disable multi
Gosub F3 ; Show the GUI

F3::Gui Show, y200, Choose

F4:: ; F4 = Enable multi
multi := True
Gui Color, Yellow
SoundBeep 1500
Return

F5:: ; F5 = Disable multi
multi := False
Gui Color, Gray
SoundBeep 1000
Check:
Gui Submit, NoHide
If InStr(sel, "|") {
 If !multi {
  GuiControl Choose, sel, 0 ; Deselect all items
  GuiControl Choose, sel, % first
  MsgBox 48, Warning, Only one item may be selected.
 }
} Else first := sel
Return

ButtonOK:
Gui Submit, NoHide
MsgBox 64, Selection, % sel
Return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], peter_ahk and 332 guests