Move ListIconGadget() item alphabetically
Move ListIconGadget() item alphabetically
What's the best way to move a given ListIconGadget() item row alphabetically? Say the list has 5 items: A,C,D,B,E. And I want to quickly move the B item to index 1 (with its icon), and without re-populating the entire list (which will lose any selected items). I can move the item easily, but not with its icon because there's no GetGadgetItemImage() command. So, any tips for me? Thank you.
Re: Move ListIconGadget() item alphabetically
For Windows
For cross platform you can use Array or List to keep text & images while creating the ListIcon (I prefer List() so you can add & remove easily)
For cross platform you can use Array or List to keep text & images while creating the ListIcon (I prefer List() so you can add & remove easily)
Code: Select all
Procedure GetImage(gadget, item)
LVITEM.LV_ITEM
LVITEM\Mask = #LVIF_IMAGE
LVITEM\iItem = item
SendMessage_(GadgetID(gadget), #LVM_GETITEM, 0, @LVITEM)
index = LVITEM\iImage
imglH = SendMessage_(GadgetID(gadget), #LVM_GETIMAGELIST, #LVSIL_SMALL, 0)
imgH = ImageList_GetIcon_(imglH, index, #ILD_TRANSPARENT)
ProcedureReturn imgH
EndProcedure
LoadImage(0, #PB_Compiler_Home+"Examples\Sources\Data\File.bmp")
LoadFont(0,"Tahoma",12)
OpenWindow(0, 0, 0, 700, 300, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(0, 10, 10, 680, 250, "Column 0", 100,#PB_ListIcon_FullRowSelect |#PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_GridLines)
SetGadgetFont(0,FontID(0))
For col = 1 To 4
AddGadgetColumn(0, col, "Column " + Str(col), 100)
Next
For row = 0 To 10
text$ = "Item :"+Str(row)+Chr(10)+"Item 2"+Chr(10)+"Item 3"+Chr(10)+"Item 4"
iimgh = 0
AddGadgetItem(0, row, Text$,iimgh)
Next
SetGadgetItemImage(0, 6, ImageID(0))
ButtonGadget(1,10,270,40,20,"RUN")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 1
sel = GetGadgetState(0)
imgH = GetImage(0, 6)
For col = 0 To 4
ntext$ = ntext$ + GetGadgetItemText(0,6,col )+Chr(10)
Next
item = 6
If sel < item
sel + 1
EndIf
RemoveGadgetItem(0,item)
AddGadgetItem(0,0, nText$ ,imgh)
SetGadgetState(0,sel)
SetActiveGadget(0)
EndSelect
EndSelect
Until Quit = 1
Egypt my love
Re: Move ListIconGadget() item alphabetically
Thank you, Rashad. Your GetImage() procedure is just what the doctor ordered.