Add to ListIcongadget alphabetically with large icons

Just starting out? Need help? Post your questions and find answers here.
BarryG
Addict
Addict
Posts: 3322
Joined: Thu Apr 18, 2019 8:17 am

Add to ListIcongadget alphabetically with large icons

Post by BarryG »

Check out this code, please. All I want to do is add "Carrot" to the list alphabetically, but it goes to the end if large icons are used. If you use small icons, it works. How can I make it work with large icons? Thank you.

Note: I can't use any auto-sorting flags (like #LVS_SORTASCENDING) because my real AddAlphabetically() procedure does more than what is shown in this snippet (I actually do other things before adding it alphabetically). So if I can just get this standalone snippet working, then my problem will be solved.

Code: Select all

Procedure AddAlphabetically(gad,text$)
  ltext$=LCase(text$)
  c=CountGadgetItems(gad)
  For item=0 To c
    If ltext$<LCase(GetGadgetItemText(gad,item))
      AddGadgetItem(gad,item,text$)
      Break
    EndIf
  Next
EndProcedure

If OpenWindow(0, 300, 200, 400, 200, "Food", #PB_Window_SystemMenu)
  ListIconGadget(0, 5, 5, 390, 190, "Name", 100)
  AddGadgetItem(0, -1, "Apple")
  AddGadgetItem(0, -1, "Banana")
  AddGadgetItem(0, -1, "Donut")
  AddGadgetItem(0, -1, "Egg")
  SetGadgetAttribute(0, #PB_ListIcon_DisplayMode, #PB_ListIcon_LargeIcon) ; Comment out to see difference.
  AddAlphabetically(0, "Carrot") ; Gets added to end if #PB_ListIcon_LargeIcon is used.
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Re: Add to ListIcongadget alphabetically with large icons

Post by RASHAD »

Hi BarryG :P

Code: Select all

Procedure AddAlphabetically(gad,text$)
SetGadgetAttribute(gad, #PB_ListIcon_DisplayMode, #PB_ListIcon_List)
  ltext$=LCase(text$)
  c=CountGadgetItems(gad)
  For item=0 To c+1
    If ltext$<LCase(GetGadgetItemText(gad,item))
      AddGadgetItem(gad,item,text$)
      Break
    EndIf
  Next
  SetGadgetAttribute(gad, #PB_ListIcon_DisplayMode, #PB_ListIcon_LargeIcon)
EndProcedure

If OpenWindow(0, 300, 200, 400, 200, "Food", #PB_Window_SystemMenu)
  ListIconGadget(0, 5, 5, 390, 190, "Name", 100)
  AddGadgetItem(0, -1, "Apple")
  AddGadgetItem(0, -1, "Banana")
  AddGadgetItem(0, -1, "Donut")
  AddGadgetItem(0, -1, "Egg")
  SetGadgetAttribute(0, #PB_ListIcon_DisplayMode, #PB_ListIcon_LargeIcon) ; Comment out to see difference.
  AddAlphabetically(0, "Carrot") ; Gets added to end if #PB_ListIcon_LargeIcon is used.
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf
Egypt my love
BarryG
Addict
Addict
Posts: 3322
Joined: Thu Apr 18, 2019 8:17 am

Re: Add to ListIcongadget alphabetically with large icons

Post by BarryG »

Hi Rashad, perfect! Thanks for that.
Post Reply