ListIconGadget with Linked List

Just starting out? Need help? Post your questions and find answers here.
doctorssh
New User
New User
Posts: 5
Joined: Sat Feb 09, 2008 7:57 am
Location: Oregon, USA

ListIconGadget with Linked List

Post 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.
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post 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
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post 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 
Post Reply