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