Disable ListIcon, but keep it interactable

Just starting out? Need help? Post your questions and find answers here.
User avatar
jacdelad
Addict
Addict
Posts: 2063
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Disable ListIcon, but keep it interactable

Post by jacdelad »

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.
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
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5029
Joined: Sun Apr 12, 2009 6:27 am

Re: Disable ListIcon, but keep it interactable

Post by RASHAD »

Hi
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
User avatar
Michael Vogel
Addict
Addict
Posts: 2839
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Disable ListIcon, but keep it interactable

Post by Michael Vogel »

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':

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 Quit
Post Reply