It is currently Sun Jul 21, 2019 1:44 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Move ListIconGadget() item alphabetically
PostPosted: Thu Jun 13, 2019 2:20 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Apr 18, 2019 8:17 am
Posts: 202
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Move ListIconGadget() item alphabetically
PostPosted: Thu Jun 13, 2019 4:15 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3354
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)
Code:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Move ListIconGadget() item alphabetically
PostPosted: Thu Jun 13, 2019 5:21 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Apr 18, 2019 8:17 am
Posts: 202
Thank you, Sir Rashad. :) Your GetImage() procedure is just what the doctor ordered.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye