ClearGadgetItems() and ListIconGadget icons

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
BarryG
Addict
Addict
Posts: 3331
Joined: Thu Apr 18, 2019 8:17 am

ClearGadgetItems() and ListIconGadget icons

Post by BarryG »

Regarding my post here -> viewtopic.php?f=13&t=74797

I would expect that ClearGadgetItems() also remove the icon column of ListIconGadgets(), as re-populating it after clearing may not have any icons included on the next populate. So can this please be added to the command, or maybe add an optional flag for it such as #PB_ListIcon_NoIconColumn? Thanks!

Here's how I'm currently doing it (thanks to Rashad in the above link):

Code: Select all

Global state = 1
Global icon = LoadImage(0, #PB_Compiler_Home + "Examples\Sources\Data\CdPlayer.ico")

Procedure ClearGadgetItemsEx(gad,withicons=0)
  hWnd = GadgetID(gad)
  SendMessage_(hWnd, #WM_SETREDRAW, 0, 0)
  ClearGadgetItems(gad)
  If withicons = 0
    size = 1
  Else
    size = 16
  EndIf
  himlIcons = SendMessage_(hWnd, #LVM_GETIMAGELIST, #LVSIL_SMALL, 0)
  ImageList_SetIconSize_(himlIcons, size, 16)
  SendMessage_(hWnd, #LVM_SETIMAGELIST, #LVSIL_SMALL, himlIcons)
  SendMessage_(hWnd, #WM_SETREDRAW, 1, 0)
EndProcedure

Procedure PopulateListIcon()
  ClearGadgetItemsEx(0,state)
  For i = 0 To 50
    AddGadgetItem(0, -1, "Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay", icon)
    AddGadgetItem(0, -1, "Ginger Brokeit"+Chr(10)+"130 PureBasic Road, BigTown, CodeCity", icon)
  Next
EndProcedure

OpenWindow(0, 100, 100, 300, 800, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

ListIconGadget(0, 5, 5, 290, 700, "Name", 150, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(0, 1, "Address", 250)
PopulateListIcon()

ButtonGadget(1, 5, 750, 290, 30, "Toggle ListIconGadget with/without icons")

Repeat
  Event = WaitWindowEvent()
  If Event = #PB_Event_Gadget And EventGadget() = 1
    state = 1 - state
    PopulateListIcon()
  EndIf
Until Event = #PB_Event_CloseWindow