ListIconGadget display corruption

Windows specific forum
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

ListIconGadget display corruption

Post by BarryG »

I've got a ListIconGadget in Large Icons mode where I added icons on-the-fly, but after adding a few, the display gets "corrupted" until I force a refresh by changing the mode from Large to List and then back to Large again.

To see what I mean, run this code. Then press the "A" key at least 8 times, and then scroll down the list and you'll see that the icons aren't in order (it has gaps, see screenshot below). Then press the "F" key to fix the display, and then "A" works normally.

I'm hoping there's a way to fix the display without changing the mode? Any ideas?

Image

Code: Select all

If OpenWindow(0, 200, 200, 320, 185, "ListIconGadget", #PB_Window_SystemMenu)
  ListIconGadget(1, 10, 10, 305, 165, "", 250, #PB_ListIcon_MultiSelect | #PB_ListIcon_AlwaysShowSelection)
  If LoadImage(0, #PB_Compiler_Home+"Examples\Sources\Data\File.bmp")
    SetGadgetAttribute(1, #PB_ListIcon_DisplayMode, #PB_ListIcon_LargeIcon)
    text$ = "Notepad"
    id = ImageID(0)
    For i = 1 To 3
      AddGadgetItem(1, 1, text$, id)
    Next
  EndIf
  Repeat
    Event = WaitWindowEvent()
    If Event = #WM_KEYUP
      Select EventwParam()
        Case #VK_A
          AddGadgetItem(1, -1, text$, id)
        Case #VK_F ; Hack "fix". How to do this without changing the DisplayMode?
          SetGadgetAttribute(1, #PB_ListIcon_DisplayMode, #PB_ListIcon_List)
          SetGadgetAttribute(1, #PB_ListIcon_DisplayMode, #PB_ListIcon_LargeIcon)
      EndSelect
    EndIf
  Until Event = #PB_Event_CloseWindow
EndIf
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4635
Joined: Sun Apr 12, 2009 6:27 am

Re: ListIconGadget display corruption

Post by RASHAD »

Hi BarryG

Code: Select all

If OpenWindow(0, 200, 200, 350, 185, "ListIconGadget", #PB_Window_SystemMenu)
  ListIconGadget(1, 10, 10, 330, 165, "", 200, #PB_ListIcon_MultiSelect | #PB_ListIcon_AlwaysShowSelection)
  If LoadImage(0, #PB_Compiler_Home+"Examples\Sources\Data\File.bmp")
    SetGadgetAttribute(1, #PB_ListIcon_DisplayMode, #PB_ListIcon_LargeIcon)
    text$ = "Notepad"
    id = ImageID(0)
    For i = 1 To 3
      AddGadgetItem(1, 1, text$, id)
    Next
  EndIf
 Repeat
    Event = WaitWindowEvent()
    If Event = #WM_KEYUP
      Select EventwParam()
        Case #VK_A
          AddGadgetItem(1, -1, text$, id)
          SendMessage_(GadgetID(1),#LVM_ARRANGE,#LVA_DEFAULT,0)
      EndSelect
    EndIf
  Until Event = #PB_Event_CloseWindow
EndIf
Egypt my love
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: ListIconGadget display corruption

Post by BarryG »

Thanks Rashad. Is that basically doing the same thing as changing the list mode, though?
breeze4me
Enthusiast
Enthusiast
Posts: 510
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Re: ListIconGadget display corruption

Post by breeze4me »

Use #LVS_AUTOARRANGE flag.

Code: Select all

If OpenWindow(0, 200, 200, 320, 185, "ListIconGadget", #PB_Window_SystemMenu)
  ListIconGadget(1, 10, 10, 305, 165, "", 250, #PB_ListIcon_MultiSelect | #PB_ListIcon_AlwaysShowSelection | #LVS_AUTOARRANGE)
  If LoadImage(0, #PB_Compiler_Home+"Examples\Sources\Data\File.bmp")
    SetGadgetAttribute(1, #PB_ListIcon_DisplayMode, #PB_ListIcon_LargeIcon)
    text$ = "Notepad"
    id = ImageID(0)
    For i = 1 To 3
      AddGadgetItem(1, 1, text$, id)
    Next
  EndIf
  Repeat
    Event = WaitWindowEvent()
    If Event = #WM_KEYUP
      Select EventwParam()
        Case #VK_A
          AddGadgetItem(1, -1, text$, id)
          
      EndSelect
    EndIf
  Until Event = #PB_Event_CloseWindow
EndIf
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: ListIconGadget display corruption

Post by BarryG »

breeze4me wrote:Use #LVS_AUTOARRANGE flag
That's even better, because I don't need to use SendMessage on the gadget every time my app's window resizes. Thank you!

See, this is exactly why I rarely mark a question as "Solved", because breeze4me might not have come into this thread if he saw it.
Post Reply