Page 1 of 2
[SOLVED] (end)User Friendly Way to delete ListIconGadget line?
Posted: Thu Oct 16, 2025 4:50 am
by Randy Walker
I have a populated listIconGadget() Where I would like to allow the user to select a line and press Delete to remove that line. Is there any way to do that without a callback? (What a Pain!) We can use the following for sample purposes:
Code: Select all
If OpenWindow(0, 100, 100, 300, 220, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(0, 5, 5, 290, 200, "Name", 100, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(0, 1, "Address", 250)
AddGadgetItem(0, -1, "Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay")
AddGadgetItem(0, -1, "Ginger Brokeit"+Chr(10)+"130 PureBasic Road, BigTown, CodeCity")
AddGadgetItem(0, -1, "Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay")
AddGadgetItem(0, -1, "Ginger Brokeit"+Chr(10)+"130 PureBasic Road, BigTown, CodeCity")
AddGadgetItem(0, -1, "Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay")
AddGadgetItem(0, -1, "Ginger Brokeit"+Chr(10)+"130 PureBasic Road, BigTown, CodeCity")
Repeat
Select WaitWindowEvent()
Case #WM_KEYDOWN
Debug "KEY down"
If GetKeyState_(#VK_DELETE)
Debug "Yep!!!"
h.i = CountGadgetItems(0)
Debug h
If h > 3
h = h-1
For e.i = h To 0 Step -1
If GetGadgetItemState(0, e)
RemoveGadgetItem(0, e)
EndIf
Next e
EndIf
EndIf
EndSelect
Until Event = #PB_Event_CloseWindow
I figured out one way using combo of #WM_KEYDOWN and GetKeyState_(#VK_DELETE) as illustrated in the revised code above.
Re: (end)User Friendly Way to delete ListIconGadget line?
Posted: Thu Oct 16, 2025 5:23 am
by BarryG
For Windows you can do it like below. Change #WM_KEYDOWN to #WM_KEYUP if you don't want the user to hold down the Delete key.
Code: Select all
If OpenWindow(0, 100, 100, 300, 300, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(0, 5, 5, 290, 290, "Number", 100, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
For i=1 To 100
AddGadgetItem(0, -1, Str(i))
Next
Repeat
Event = WaitWindowEvent()
If Event = #WM_KEYDOWN And EventwParam() = #VK_DELETE
i = GetGadgetState(0)
RemoveGadgetItem(0, i)
SetGadgetState(0, i)
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
Re: (end)User Friendly Way to delete ListIconGadget line?
Posted: Thu Oct 16, 2025 5:47 am
by Randy Walker
BarryG wrote: Thu Oct 16, 2025 5:23 am
For Windows you can do it like below. Change #WM_KEYDOWN to #WM_KEYUP if you don't want the user to hold down the Delete key.
Ok, Your way is much cleaner than the method I figured out above. Thanks BarryG
Re: [SOLVED] (end)User Friendly Way to delete ListIconGadget line?
Posted: Thu Oct 16, 2025 8:12 am
by Mindphazer
The same code, but cross platform :
Code: Select all
Enumeration
#KeyDelete
EndEnumeration
If OpenWindow(0, 100, 100, 300, 300, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
AddKeyboardShortcut(0, #PB_Shortcut_Delete, #KeyDelete)
ListIconGadget(0, 5, 5, 290, 290, "Number", 100, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
For i=1 To 100
AddGadgetItem(0, -1, Str(i))
Next
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Menu And EventMenu() = #KeyDelete
i = GetGadgetState(0)
RemoveGadgetItem(0, i)
SetGadgetState(0, i)
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
Re: [SOLVED] (end)User Friendly Way to delete ListIconGadget line?
Posted: Thu Oct 16, 2025 12:08 pm
by BarryG
Mindphazer wrote: Thu Oct 16, 2025 8:12 amAddKeyboardShortcut(0, #PB_Shortcut_Delete, #KeyDelete)
But then you can't use the Delete key in your app, such as when using a StringGadget.
Re: [SOLVED] (end)User Friendly Way to delete ListIconGadget line?
Posted: Thu Oct 16, 2025 12:25 pm
by spikey
BarryG wrote: Thu Oct 16, 2025 12:08 pm
But then you can't use the Delete key in your app, such as when using a StringGadget.
You can chop and change shortcuts at will:
Code: Select all
Enumeration
#KeyDelete
EndEnumeration
If OpenWindow(0, 100, 100, 300, 500, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(0, 5, 5, 290, 290, "Number", 100, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
For i=1 To 100
AddGadgetItem(0, -1, Str(i))
Next
StringGadget(1, 5, 305, 290, 25, "Edit me!")
EditorGadget(2, 5, 335, 290, 100)
SetGadgetText(2, "And me too!")
Repeat
Event = WaitWindowEvent()
If GetActiveGadget() = 0
AddKeyboardShortcut(0, #PB_Shortcut_Delete, #KeyDelete)
Else
RemoveKeyboardShortcut(0, #PB_Shortcut_Delete)
EndIf
If Event = #PB_Event_Menu And EventMenu() = #KeyDelete
i = GetGadgetState(0)
If i > -1
RemoveGadgetItem(0, i)
SetGadgetState(0, i)
EndIf
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
Re: [SOLVED] (end)User Friendly Way to delete ListIconGadget line?
Posted: Thu Oct 16, 2025 1:03 pm
by AZJIO
First, make sure that the item is selected.
Re: [SOLVED] (end)User Friendly Way to delete ListIconGadget line?
Posted: Thu Oct 16, 2025 1:07 pm
by Mindphazer
@spikey
Very nice !
Re: [SOLVED] (end)User Friendly Way to delete ListIconGadget line?
Posted: Thu Oct 16, 2025 1:13 pm
by spikey
AZJIO wrote: Thu Oct 16, 2025 1:03 pm
First, make sure that the item is selected.
That's a good point. There's a potential runtime error there, if you don't.
Mindphazer wrote: Thu Oct 16, 2025 1:07 pm
@spikey
Very nice !

Thank you!
Re: [SOLVED] (end)User Friendly Way to delete ListIconGadget line?
Posted: Thu Oct 16, 2025 7:48 pm
by Randy Walker
Mindphazer wrote: Thu Oct 16, 2025 8:12 am
The same code, but cross platform :
Tested on Win 11 and works great. Thank you for the contributuion Mindphaser!!! Fred should add that snippet to the Help doc.
Re: [SOLVED] (end)User Friendly Way to delete ListIconGadget line?
Posted: Thu Oct 16, 2025 8:14 pm
by Randy Walker
Mindphazer wrote: Thu Oct 16, 2025 1:07 pm
@spikey
Very nice !
I double that. OKay then... Fred should put spikey's snippet into the Help doc under RemoveGadgetItem since there is no sample code there now. Yeah Yeah!! That would be great! Thanks Fred!!!
Re: [SOLVED] (end)User Friendly Way to delete ListIconGadget line?
Posted: Mon Oct 20, 2025 8:43 pm
by Andre
Example added to the docs

Re: [SOLVED] (end)User Friendly Way to delete ListIconGadget line?
Posted: Tue Oct 21, 2025 7:21 pm
by Randy Walker
Re: [SOLVED] (end)User Friendly Way to delete ListIconGadget line?
Posted: Tue Oct 21, 2025 11:53 pm
by RASHAD
Hi All
This is my 2 cents
Delete is specific for the ListIcon only
Code: Select all
If OpenWindow(0, 100, 100, 300, 300, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(0, 5, 5, 290, 260, "Number", 100, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
For i=1 To 100
AddGadgetItem(0, -1, Str(i))
Next
StringGadget(1,5,270,290,24,"This is a test")
AddWindowTimer(0,125,50)
Repeat
Select WaitWindowEvent(1)
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Timer
If GetActiveGadget() = 0
AddKeyboardShortcut(0, #PB_Shortcut_Delete,10)
Else
RemoveKeyboardShortcut(0, #PB_Shortcut_Delete)
EndIf
Case #PB_Event_Menu
Select EventMenu()
Case 10
item = GetGadgetState(0)
If item <> -1
RemoveGadgetItem(0, item)
EndIf
EndSelect
EndSelect
Until Quit = 1
EndIf
Re: [SOLVED] (end)User Friendly Way to delete ListIconGadget line?
Posted: Wed Oct 22, 2025 8:16 pm
by Randy Walker
Hi Rashad... Works great (as usual) , but can you explain the "Case 10"? Where did you get "10" from?