Page 1 of 1

ListIconGadget with Linked List

Posted: Tue Apr 01, 2008 5:58 am
by doctorssh
I'm displaying a Linked List data set within a ListIconGadget. By clicking on a line within the ListIcon, the line is highlighted.

Please tell me how to "capture" that action (click) and also how to "capture" the line number (record within the Linked List).

I'd like to be able to highlight a line, then click on an "delete" button on the pull-down menu ... and remove that line from the Linked List. Much like I can do with a spreadsheet in (say) Excel.

Thanks for the help.

Posted: Tue Apr 01, 2008 12:56 pm
by rsts
Have you looked at the help file under listicongadget? I believe this will get you started. Or is there something in it you don't understand?

Also 'search' is your friend.
:)

cheers

Posted: Tue Apr 01, 2008 7:23 pm
by rsts
you detect a selected item via Result = GetGadgetItemState(#Gadget, Item. (you do have an event loop, I hope? If not we need to drop back a little farther) - :)

To associate it with an item in a linked list you could include a pointer to the element in the linked list as 'data' in the listicongadget.
see - SetGadgetItemData(#Gadget, Item, Value)
and GetGadgetItemData(#Gadget, Item, Value)

Does this get you started?

Welcome to PureBasic.

cheers

edit - I'm sure the experts can improve on this but it covers some of the basics

Code: Select all


;create a file of data
If CreateFile(0, "test.txt") 
  WriteStringN(0,"Item 1") 
  WriteStringN(0,"Item 2") 
  WriteStringN(0,"Item 3 ") 
  WriteStringN(0,"item 4") 
  WriteStringN(0,"Item 5") 
  CloseFile(0) 
EndIf 

;now open it up and read it into a linkedlist 
NewList myString.s() 
If OpenFile(0,"test.txt") 
  While Not Eof(0) 
    AddElement(myString()) 
    myString()=ReadString(0) 
  Wend 

  CloseFile(0) 
EndIf 

OpenWindow(0,0,0,540,480,"Welcome to PureBasic, doctorsh",#PB_Window_SystemMenu|#PB_Window_ScreenCentered) 
CreateGadgetList(WindowID(0)) 
ListIconGadget(0,50,50,400,400,"Item",236,#PB_ListIcon_GridLines|#PB_ListIcon_AlwaysShowSelection ) 


;fill the gadget from the list 
ForEach myString() 

  AddGadgetItem(0, -1, myString()) 
  SetGadgetItemData(0,Count,@myString())
  Debug PeekL(@myString())
   Count+1 
Next
  Count-1 ; to reflect the item count 
  MessageRequester("","Now display in debugger") 
SetGadgetItemState(0, 0, #PB_ListIcon_Selected) 
Repeat 
  Event = WaitWindowEvent() 
  Select EventGadget()
      
    Case 0 ; listicongadget
      While Count>=0
        
        *mypointer = GetGadgetItemData(0,Count);retrieves the stored pointer 
        
        Debug PeekS(PeekL(*mypointer) )
      Count-1 
      
    Wend 
    EndSelect
Until Event = #PB_Event_CloseWindow