Disable ListIcon, but keep it interactable
Disable ListIcon, but keep it interactable
Hi,
is there an easy way to disable a ListIconGadget, but keep it interactable? Like a readonly EditorGadget, no changes can be made, but it's scrollable. I want the ListIcon to be scrollable, but no changes made to the selected elements.
I know how to do this via subclassing on Windows, but maybe there's an easier way.
is there an easy way to disable a ListIconGadget, but keep it interactable? Like a readonly EditorGadget, no changes can be made, but it's scrollable. I want the ListIcon to be scrollable, but no changes made to the selected elements.
I know how to do this via subclassing on Windows, but maybe there's an easier way.
Good morning, that's a nice tnetennba!
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/2*DX517, 164TB+82TB+28TB+2TB SSD
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/2*DX517, 164TB+82TB+28TB+2TB SSD
Re: Disable ListIcon, but keep it interactable
Hi
Workaround
Workaround
Code: Select all
If OpenWindow(0, 0, 0, 800, 600, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
lic1 = ListIconGadget(#PB_Any, 10, 10, 780, 540, "Name", 150, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
lic2 = ListIconGadget(#PB_Any, 0, 0, 0, 0, "Name", 150, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(lic1, 1, "Address", 350)
For i = 0 To 100
AddGadgetItem(lic1, -1, Str(i)+" Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay")
Next
ButtonGadget(0,10,560,120,24,"Disable")
ButtonGadget(1,140,560,120,24,"Remove")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 0
disflag ! 1
Debug disflag
If disflag = 1
Swap lic1,lic2
SetGadgetText(0,"Enable")
SetGadgetColor(lic2,#PB_Gadget_BackColor,$D6D6D6)
Else
Swap lic1,lic2
SetGadgetText(0,"Disable")
SetGadgetColor(lic1,#PB_Gadget_BackColor,#PB_Default)
EndIf
Case 1
RemoveGadgetItem(lic1,2)
EndSelect
EndSelect
Until Quit = 1
EndIf
Egypt my love
- Michael Vogel
- Addict

- Posts: 2840
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Re: Disable ListIcon, but keep it interactable
No idea what is needed as listicons can only be edited by writing code for it, so here you have to check if it is allowed or not...
Using Rashad's code to demonstrate the shortcut 'R' won't work when the listicon gadget gets 'disabled':
Using Rashad's code to demonstrate the shortcut 'R' won't work when the listicon gadget gets 'disabled':
Code: Select all
OpenWindow(0, 0, 0, 800, 600, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(0,10,560,120,24,"Disable")
ButtonGadget(1,140,560,120,24,"Remove")
txt1= TextGadget(#PB_Any,10,10,200,25,"Your List:")
lic1= ListIconGadget(#PB_Any, 10, 40, 780, 500, "Name", 150, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(lic1, 1, "Address", 350)
For i = 0 To 100
AddGadgetItem(lic1, -1, Str(i)+" Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay")
Next
AddKeyboardShortcut(0,#PB_Shortcut_D,0)
AddKeyboardShortcut(0,#PB_Shortcut_R,1)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget,#PB_Event_Menu
Select EventGadget()
Case 0
disflag ! 1
If disflag = 1
SetGadgetText(0,"Enable")
Else
SetGadgetText(0,"Disable")
EndIf
SetGadgetText(txt1,"Your List"+StringField(":. (locked):",disflag+1,"."))
DisableGadget(1,disflag)
Case 1
If disflag=0
RemoveGadgetItem(lic1,2)
Else
Debug "Locked"
EndIf
EndSelect
EndSelect
Until QuitRe: Disable ListIcon, but keep it interactable
Thanks for the codes. Sorry for not expressing what I want: With "editing it" I meant not being able to select elements or change checkboxes.
Good morning, that's a nice tnetennba!
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/2*DX517, 164TB+82TB+28TB+2TB SSD
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/2*DX517, 164TB+82TB+28TB+2TB SSD
Re: Disable ListIcon, but keep it interactable
Hi
Edit :Code modified for more enhancements
Code: Select all
Procedure winCB(hWnd,uMsg,wParam,lParam)
Result = #PB_ProcessPureBasicEvents
Select uMsg
Case #WM_SIZE,#WM_MOVE
ResizeGadget(0,10,10,WindowWidth(0)-20,WindowHeight(0)-60)
ResizeGadget(2,10,WindowHeight(0)-40,#PB_Ignore,#PB_Ignore)
ResizeWindow(10,GadgetX(0,#PB_Gadget_ScreenCoordinate),GadgetY(0,#PB_Gadget_ScreenCoordinate),GadgetWidth(0)-20,GadgetHeight(0))
EndSelect
ProcedureReturn Result
EndProcedure
If OpenWindow(0, 0, 0, 800, 600, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered|#PB_Window_SizeGadget)
ListIconGadget(0, 10, 10, 780, 540, "Name", 150, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_CheckBoxes )
AddGadgetColumn(0, 1, "Address", 350)
For i = 0 To 100
AddGadgetItem(0, -1, Str(i)+" Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay")
Next
ButtonGadget(2,10,560,120,24,"Enable")
OpenWindow(10,GadgetX(0,#PB_Gadget_ScreenCoordinate),GadgetY(0,#PB_Gadget_ScreenCoordinate),GadgetWidth(0)-20,GadgetHeight(0),"",#PB_Window_BorderLess )
SetWindowLongPtr_(WindowID(10),#GWL_EXSTYLE,#WS_EX_LAYERED)
SetLayeredWindowAttributes_(WindowID(10),0,1,#LWA_ALPHA)
SetWindowLongPtr_( WindowID(10), #GWL_HWNDPARENT,WindowID(0))
SetWindowCallback(@winCB())
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 2
disflag ! 1
HideWindow(10,disflag)
If disflag = 1
SetGadgetText(2,"Disable")
Else
SetGadgetText(2,"Enable")
EndIf
EndSelect
EndSelect
Until Quit = 1
EndIf
Egypt my love
Re: Disable ListIcon, but keep it interactable
Thanks RASHAD, that's basically how I do it. I just thought it would be possible without subclassing.
Good morning, that's a nice tnetennba!
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/2*DX517, 164TB+82TB+28TB+2TB SSD
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/2*DX517, 164TB+82TB+28TB+2TB SSD
- Michael Vogel
- Addict

- Posts: 2840
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Re: Disable ListIcon, but keep it interactable
It is, but not very elegant...
Code: Select all
Global disflag=0
Global Dim state(0)
Procedure Test()
Protected e
If disflag
e=CountGadgetItems(0)
While e
e-1
SetGadgetItemState(0,e,state(e))
Wend
SetGadgetState(0,-1)
EndIf
EndProcedure
If OpenWindow(0, 0, 0, 800, 600, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered|#PB_Window_SizeGadget)
ListIconGadget(0, 10, 10, 780, 540, "Name", 150, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_CheckBoxes )
AddGadgetColumn(0, 1, "Address", 350)
For i = 0 To 100
AddGadgetItem(0, -1, Str(i)+" Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay")
Next
ButtonGadget(2,10,560,120,24,"Enabled")
BindEvent(#PB_Event_Gadget,@test(),0,0,#PB_EventType_Change)
; PostEvent(#PB_Event_Gadget,0,2)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 2
If disflag
SetGadgetText(2,"Enabled")
Else
SetGadgetText(2,"Disabled")
i=CountGadgetItems(0)
ReDim state(i)
While i
i-1
state(i)=GetGadgetItemState(0,i)
Wend
EndIf
disflag ! 1
EndSelect
EndSelect
Until Quit = 1
EndIf
Re: Disable ListIcon, but keep it interactable
It works well and seems more elegant than having to go through SetWindowCallback()
You can just add SetGadgetState(0,-1) after SetGadgetText(2,"Disabled") otherwise, we can reselect the previous selection without calling test() callback
Re: Disable ListIcon, but keep it interactable
No Window callback
You can use ScrollBarGadget() instead of Button 3 and 4
Code: Select all
Procedure sizemove()
ResizeGadget(0,10,10,WindowWidth(0)-20,WindowHeight(0)-60)
ResizeGadget(2,10,WindowHeight(0)-40,#PB_Ignore,#PB_Ignore)
ResizeWindow(10,GadgetX(0,#PB_Gadget_ScreenCoordinate),GadgetY(0,#PB_Gadget_ScreenCoordinate),GadgetWidth(0)-20,GadgetHeight(0))
EndProcedure
If OpenWindow(0, 0, 0, 800, 600, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered|#PB_Window_SizeGadget)
ListIconGadget(0, 10, 10, 780, 540, "Name", 150, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_CheckBoxes )
AddGadgetColumn(0, 1, "Address", 350)
For i = 0 To 100
AddGadgetItem(0, -1, Str(i)+" Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay")
Next
ButtonGadget(2,10,560,120,24,"Enable")
OpenWindow(10,GadgetX(0,#PB_Gadget_ScreenCoordinate),GadgetY(0,#PB_Gadget_ScreenCoordinate),GadgetWidth(0)-20,GadgetHeight(0),"",#PB_Window_BorderLess )
SetWindowLongPtr_(WindowID(10),#GWL_EXSTYLE,#WS_EX_LAYERED)
SetLayeredWindowAttributes_(WindowID(10),0,1,#LWA_ALPHA)
SetWindowLongPtr_( WindowID(10), #GWL_HWNDPARENT,WindowID(0))
BindEvent(#PB_Event_SizeWindow,@sizemove())
BindEvent(#PB_Event_MoveWindow,@sizemove())
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 2
disflag ! 1
HideWindow(10,disflag)
If disflag = 1
SetGadgetText(2,"Disable")
Else
SetGadgetText(2,"Enable")
EndIf
EndSelect
EndSelect
Until Quit = 1
EndIf
Code: Select all
#OBJID_HSCROLL= $FFFFFFFA
#OBJID_VSCROLL= $FFFFFFFB
#OBJID_CLIENT = $FFFFFFFC
Structure SCROLLBARINFO Align #PB_Structure_AlignC
cbSize.l
rcScrollBar.RECT
dxyLineButton.l
xyThumbTop.l
xyThumbBottom.l
reserved.l
rgstate.l[6]
EndStructure
LoadFont(0,"Marlett",14)
If OpenWindow(0, 0, 0, 800, 600, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(0, 10, 10, 780, 540, "Name", 150, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_CheckBoxes )
AddGadgetColumn(0, 1, "Address", 350)
For i = 0 To 100
AddGadgetItem(0, -1, Str(i)+" Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay")
Next
item_h = SendMessage_(GadgetID(0), #LVM_GETITEMSPACING, #True, 0) >> 16
ButtonGadget(2,10,560,120,24,"Enable")
ButtonGadget(3,140,560,24,24,Chr(53))
SetGadgetFont(3,FontID(0))
ButtonGadget(4,174,560,24,24,Chr(54))
SetGadgetFont(4,FontID(0))
sc.SCROLLBARINFO
Sc\cbSize=SizeOf(sc)
DisableGadget(0,1)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 2
disflag ! 1
If disflag = 1
DisableGadget(0,0)
SetGadgetText(2,"Disable")
Else
SetGadgetState(0,-1)
DisableGadget(0,1)
SetGadgetText(2,"Enable")
EndIf
Case 3
If disflag = 0
SendMessage_(GadgetID(0), #LVM_SCROLL, 0, -1 * Item_H)
GetScrollBarInfo_(GadgetID(0),#OBJID_VSCROLL,@Sc)
magic = Sc\xyThumbBottom - Sc\xyThumbTop
EndIf
Case 4
If disflag = 0
SendMessage_(GadgetID(0), #LVM_SCROLL, 0, 1 * Item_H)
GetScrollBarInfo_(GadgetID(0),#OBJID_VSCROLL,@Sc)
magic = Sc\xyThumbBottom - Sc\xyThumbTop
EndIf
EndSelect
EndSelect
Until Quit = 1
EndIf
Egypt my love
Re: Disable ListIcon, but keep it interactable
I like the first one with the BorderLess window width - GetSystemMetrics_(#SM_CXHTHUMB) and SetLayeredWindowAttributes_(WinID,0,1,#LWA_ALPHA)
Works but scrolling with the mouse wheel is missing.
otherwise, the same as Michael but with Gadget Item Data
Edit: Add Disabled Gadget Back Color
Works but scrolling with the mouse wheel is missing.
otherwise, the same as Michael but with Gadget Item Data
Code: Select all
Global disflag
Procedure Test()
Protected e
If disflag
e=CountGadgetItems(0)
While e
e-1
SetGadgetItemState(0, e, GetGadgetItemData(0, e))
Wend
SetGadgetState(0, -1)
EndIf
EndProcedure
If OpenWindow(0, 0, 0, 800, 600, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
ListIconGadget(0, 10, 10, 780, 540, "Name", 150, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection | #PB_ListIcon_CheckBoxes )
AddGadgetColumn(0, 1, "Address", 350)
For i = 0 To 100
AddGadgetItem(0, -1, Str(i) + " Harry Rannit" +#LF$+ Str(i) + " Parliament Way, Battle Street, By the Bay")
Next
ButtonGadget(1, 10, 560, 120, 24, "Disabled")
BindGadgetEvent(0, @test(), #PB_EventType_Change)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 1
If disflag
SetGadgetText(1, "Disabled")
SetGadgetColor(0, #PB_Gadget_BackColor, #PB_Default)
Else
SetGadgetText(1, "Enabled")
SetGadgetState(0, -1)
SetGadgetColor(0, #PB_Gadget_BackColor, $F0F0F0)
i=CountGadgetItems(0)
While i
i-1
SetGadgetItemData(0, i, GetGadgetItemState(0, i))
Wend
EndIf
disflag ! 1
EndSelect
EndSelect
Until Quit = 1
EndIf
Last edited by ChrisR on Mon Jan 26, 2026 2:51 pm, edited 2 times in total.
Re: Disable ListIcon, but keep it interactable
Search the forum for Sync 2 Listicon
Adapt it for your needs so you can use Mouse Wheel ,Key down,Key up and thump as well
But you have to use SetWindowCallBack()
Adapt it for your needs so you can use Mouse Wheel ,Key down,Key up and thump as well
But you have to use SetWindowCallBack()
Egypt my love
