PureBasic Forum
http://forums.purebasic.com/english/

ListViewGadget - What wrong with this code
http://forums.purebasic.com/english/viewtopic.php?f=10&t=18671
Page 1 of 1

Author:  leodh [ Sat Jan 14, 2006 2:04 am ]
Post subject:  ListViewGadget - What wrong with this code

Hi,

I am having some trouble with the ListViewGadget, I can not get it to update properly.

Here is the code,

Structure ListView

Pad.w
String.s
EndStructure

NewList MyListView.ListView()

WBStartup()

If InitTagList(10)
InitGadget(10)

Title.s="ListView Gadget Test"

OpenWindow(0,20,80,200,450,#WFLG_DRAGBAR|#WFLG_CLOSEGADGET,Title.s)

For c.l=0 To 29
AddElement(MyListView())
MyListView()\String="Label "+Str(c.l)
Next

CreateGadgetList()
ButtonGadget(1,30,275,120,25,"New List")
ButtonGadget(2,30,310,120,25,"Old List")

ListViewGadget(3,20,20,150,250,"",ListBase(MyListView()))
ResetTagList(#GTTX_Border,1) : SetGadgetTagList(TagListID())

TextGadget(4,30,345,120,25,0,"")
ResetTagList(#GTTX_Border,1) : SetGadgetTagList(TagListID())
TextGadget(5,30,380,120,25,0,"")
RefreshGadget(-1)

Repeat
Event.l = WaitWindowEvent()
If Event = #IDCMP_GADGETDOWN Or Event = #IDCMP_GADGETUP
EventGadget.l=EventGadgetID()
GadgetState.l=GetGadgetState(EventGadget)
Select EventGadget
Case 1 ; New List
ClearList(MyListView())
FirstElement(MyListView())
For c.l=0 To 59
AddElement(MyListView())
MyListView()\String="Label "+Str(c.l)
Next
List$="New List"
New$= Str(CountList(MyListView()))
ResetTagList(#GTLV_MakeVisible,CountList(MyListView())) : SetGadgetAttribute(3,TagListID())
RefreshGadget(-1)
Case 2 ; Old List
ClearList(MyListView())
FirstElement(MyListView())
For c.l=0 To 29
AddElement(MyListView())
MyListView()\String="Label "+Str(c.l)
Next
List$="Old List"
New$= Str(CountList(MyListView()))
ResetTagList(#GTLV_MakeVisible,CountList(MyListView())) : SetGadgetAttribute(3,TagListID())
RefreshGadget(-1)
Case 3
New$="ListView gadget: "+Str(GadgetState)
SetGadgetState(3,-1)
EndSelect
If New$ <> ""
SetGadgetText(4,List$)
Text$=New$
SetGadgetText(5,Text$)
New$=""
EndIf
EndIf
Until Event = #IDCMP_CLOSEWINDOW
EndIf
End

How do I get it to refresh the content of the ListViewGadget.

Any help would be great.

Author:  oakvalley [ Wed Apr 19, 2017 11:05 pm ]
Post subject:  Re: ListViewGadget - What wrong with this code

Hi Leodh,

Can't believe why anybody didn't respond to this, as my investigations for the past 4 days reveal a major bug or did I do something wrong?
Anyway, this code explains how to get listview to update both list and scrollbars, if items are added or deleted.

Naturally I come from a Windows purebasic reality since 2003 and never tried the Amiga version, until this easter. But the faulty editor of PB4.0 makes me headache, especially this bug made me wonder how the heck a major release of Amiga PureBasic could leave such a huge mistake unsolved.

If anybody can take's Leodh's code or mine and prove us wrong, then please give us an example of how to get listview working correctly.
Possibly one could Poke any of the Str, Left, Right string commands into a memory bank and peeks it back into the listview output, not tried, but possibly works too.

Code:
WBStartup()
InitGadget(4)

; Demo of listview bug in PureBasic 4.0
; 1: Using Left, Right, Mid and Str (possibly more commands related to strings) and listview dont update. I can't see why they would interfere!
; 2: #GTLV_Labels are the tag to be used, but not mentioned in PB Docs
; 3: #GTLV_MakeVisible dont do anything as we would suspect from PB Docs. Don't know what it does really....
; 4: #GTLV_Labels are seen in previous PB .guides versions, why was it removed in PB4.0?! Without it, listview would work ONCE pr startup, never later during code running.


Structure NLVList
  Pad.w
  Item.s
EndStructure
NewList PL.NLVList()

OpenWindow(0,210,20,416,298,#WFLG_CLOSEGADGET|#WFLG_DRAGBAR|#WFLG_DEPTHGADGET,"Listview BUG 2017")
CreateGadgetList()
InitTagList(0)
   
ListViewGadget(1,12,50,100,100,0,ListBase(PL()))
ButtonGadget(2,12,10,49,20,"Add")
ButtonGadget(3,63,10,49,20,"Del")
RefreshGadget(-1)

Repeat
    event.l=WaitWindowEvent()
    Gadget=EventGadgetID()
   
    If event=#IDCMP_GADGETUP OR IDCMP=#IDCMP_GADGETDOWN
       Select Gadget
              Case 2 ; 'Add'
                   For t=0 To 15
                       AddElement(PL())
                       PL()\Item = "Hey There"
                       ResetTagList(#GTLV_Labels,ListBase(PL()))
                       SetGadgetAttribute(1,TagListID())
                       RefreshGadget(1)
                       Delay(5)
                       cc=0
                       
                       ;Uncomment below and scrollbar of listview gets no update!
                      ; PrintN(Str(t))
                   Next t
                   
              Case 3 ; 'Del'
                   FirstElement(PL())
                   While NextElement(PL())
                         cc=cc+1
                         KillElement(PL())
                         ResetTagList(#GTLV_Labels,ListBase(PL()))
                         SetGadgetAttribute(1,TagListID())
                         RefreshGadget(1)
                         Delay(5)
                                       
                         ;Uncomment below and scrollbar of listview gets no update!               
                         ;Print(Str(cc))
                   Wend
                   KillElement(PL())
                   ResetTagList(#GTLV_Labels,ListBase(PL()))
                   SetGadgetAttribute(1,TagListID())
                   RefreshGadget(1)
       EndSelect
     EndIf
Until event=#IDCMP_CLOSEWINDOW
End

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/