Add text to a ListBox Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
TrevorBo
Posts: 7
Joined: 15 Jan 2023, 11:28

Add text to a ListBox

Post by TrevorBo » 30 Jan 2023, 07:13

I have a script that allows users to enter text which is stored in a file in formatted manner and that works nicely. However, I want to be able to show users what they have entered so far so I set up a listbox with the intention of appending text to it each time the user made an entry. I have been unable to make this work. If someone can point out where I am going wrong it would be greatly appreciated. Code to show what I am trying to do below:

Code: Select all

sLBTimelineItems := ""

;------------------------------------------------------------------------------
; Template for main window
Gui, Add, Button, x12 yp+30 w100 h30 Section Default, Add Timeline Item
Gui, Add, ListBox, xp+110 yp w200 r10 vsLBTimelineItems, %sTimelineItems%
Gui, Show, x400 y200 h200 w350, ListBox Test

;------------------------------------------------------------------------------
; Template for Add Timeline Item  sub-window
Gui AddTLIWindow:New
Gui, Add, Text,   x12   ym,            Timeline Item
Gui, Add, Edit,   x12   yp+20 w180  r1 vsTimelineItem
Gui, Add, Button, x100  yp+40 w100 h30 gAddTLISaveItem, Save Item
return

;------------------------------------------------------------------------------
; Labels Section
ButtonAddTimelineItem:  
	Gui AddTLIWindow:Default
	Send ^a
	Gui Show, x600, Add Timeline Item
	Return

AddTLISaveItem:
	Gui Submit
	MsgBox Row item=%sTimelineItem%   
	
	sOtherTimelineItems := "new timeline item"
	GuiControl,, sLBOtherTimelineItems, |%sTimelineItem%  
	GuiControl +Default, Save
	Return
	
GuiClose:
ExitApp

[Mod edit: Added [code][/code] tags. Please use them yourself when posting code! This is not meant to be a service provided by the moderators.]

User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: Add text to a ListBox  Topic is solved

Post by mikeyww » 30 Jan 2023, 08:18

Code: Select all

; This script adds items to a listbox
#Requires AutoHotkey v1.1.33
Gui Font, s10
Gui Add, Button , w200 Default, Add Timeline Item
Gui Add, ListBox, wp   r10 vlist
Gui Show, x1000, Timeline
Gui Add:New
Gui Font, s10
Gui Add, Text  ,              , Timeline Item:
Gui Add, Edit  , w180  vitem
Gui Add, Button, wp    Default, Save Item
Return

ButtonAddTimelineItem:
Gui Add:Default
Gui Show, x600, Add Timeline Item
Return

AddButtonSaveItem:
Gui Submit
GuiControl, 1:, list, % list .= item = "" ? "" : "|" item
GuiControl,, item
Return

GuiClose:
ExitApp
Or:

Code: Select all

; This script adds items to a listbox
#Requires AutoHotkey v1.1.33
Gui Font, s10
Gui Add, Edit   , w200 vitem gCheck
Gui Add, Button , wp   Default Disabled, Add
Gui Add, ListBox, wp   vlist r10
Gui Show, x1000, Timeline
Return

Check:
Gui Submit, NoHide
GuiControl, % item = "" ? "Disable" : "Enable", Add
Return

ButtonAdd:
Gui Submit, NoHide
GuiControl,, list, % txt .= "|" item
GuiControl,, item
Return

GuiClose:
ExitApp

Code: Select all

; This script adds items to a listbox
#Requires AutoHotkey v2.0
check := (*) => btn.Enabled := item.Value = "" ? False : True
gui1  := Gui(, 'Timeline')
gui1.SetFont('s10')
item  := gui1.AddEdit('w200')
btn   := gui1.AddButton('wp Default Disabled', 'Add')
list  := gui1.AddListBox('wp r10')
item.OnEvent('Change', check)
btn.OnEvent('Click'  , (*) => (list.Add([item.Value]), item.Value := "", check()))
gui1.Show('x1000')

TrevorBo
Posts: 7
Joined: 15 Jan 2023, 11:28

Re: Add text to a ListBox

Post by TrevorBo » 30 Jan 2023, 12:21

Thanks for your help again Mike.

Most appreciated.

Post Reply

Return to “Ask for Help (v1)”