Scrolling ListViewGadget

Everything else that doesn't fall into one of the other PB categories.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by TerryHough.

Can anyone tell me how to get the ListViewGadget to automatically
down to the last item listed?

The vertical scroll bar creates automatically when the box
is filled, but the view remains at the top.

Is there a command to issue to have the ListView automatically scroll?

Thanks,
Terry
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

Use SetGadgetState():

Code: Select all

OpenWindow(1,10,10,300,300,#PB_Window_SystemMenu,"ListView Test")
CreateGadgetList(WindowID())
ListViewGadget(1,0,0,300,300)


For a = 0 To 2000
    AddGadgetItem(1,-1,"ListView Entry "+Str(a))
Next a


SetGadgetState(1,2000)


Repeat
Until WaitWindowEvent() = #PB_EventCloseWindow
cya,
...Danilo

(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by TerryHough.

Thanks Danilo

You pointed me to a solution to the problem. I was using
SetGadgetState but in this manner since I have no idea how many
items there are:
MoveToEnd = SetGadgetState(1, CountGadgetItems(1))

But see you example modifed on one line

Code: Select all

OpenWindow(1,10,10,300,300,#PB_Window_SystemMenu,"ListView Test")
CreateGadgetList(WindowID())
ListViewGadget(1,0,0,300,300)

For a = 0 To 2000
    AddGadgetItem(1,-1,"ListView Entry "+Str(a))
Next a

; see this line --------------------------------------
MoveToEnd = SetGadgetState(1, CountGadgetItems(1) - 1)

Repeat
Until WaitWindowEvent() = #PB_EventCloseWindow

This works successfully.

I had expected the CountGadgetItems to return the index of
the last item. See the help description below:

Syntax

Result = CountGadgetItems(#Gadget)
Description

Returns the number of items in the specified #Gadget. The first item index is starting from 1. If the #Gadget doesn't contain any items, 0 is returned.

Apparently, it returns the number of the next available item. Or I just
don't read it correctly.

Your code worked because you actually wrote 2001 items and then set the gadget
state on 2000. But it made me think and reach a solution. Thanks for your
help.

Unfortunately, this is a cludge. I was hoping there is a "flag" to set
that causes the ListViewGadget to automatically scroll. I know very little
about the API, but have worked with other languages where this was an option
for a ListView.

Fred? Maybe you can enlighten me.

Thanks for your help.
Terry
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

The commands are all ZERO-based (beginning with 0),
but CountGadgetItems() isnt.
Thats logical, because it returns the count of all items (including 0).

cya,
...Danilo

(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by TerryHough.
Originally posted by Danilo

Use SetGadgetState():

Code: Select all

OpenWindow(1,10,10,300,300,#PB_Window_SystemMenu,"ListView Test")
CreateGadgetList(WindowID())
ListViewGadget(1,0,0,300,300)


For a = 0 To 2000
    AddGadgetItem(1,-1,"ListView Entry "+Str(a))
Next a


SetGadgetState(1,2000)


Repeat
Until WaitWindowEvent() = #PB_EventCloseWindow
cya,
...Danilo

(registered PureBasic user)
This technique doesn't work with the ListIconGadget for me.

Any pointers on how to get the ListIconGadget to scroll to the
item selected with SetGadgetState?

Thanks in advance,
Terry
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Paul.

Hey Terry, this works for me...

Code: Select all

hWnd=OpenWindow(0,10,10,300,200,#PB_Window_SystemMenu,"ListView")
If hWnd=0 Or CreateGadgetList(hWnd)=0:End:EndIf
 
ButtonGadget(1,230,175,60,20,"Item 50")
LI=ListIconGadget(2,10,10,280,160,"Name",100,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect) 
 
For tmp=0 To 100
  AddGadgetItem(2,tmp,"Test "+Str(tmp))
Next    
     
Repeat
  eventid=WaitWindowEvent()
  If eventid=#PB_EventGadget
    If EventGadgetID()=1
      SendMessage_(LI,#LVM_ENSUREVISIBLE,50,0)
      SetGadgetState(2,50)
    EndIf
  EndIf 
Until eventid=#PB_Event_CloseWindow
This example selects item #50 when you press the button.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Justin.

I think this partyally solves a problem a asked before regarding to not show partial items in a listicon, it was easy, thanks.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by TerryHough.
Originally posted by Paul

Hey Terry, this works for me...
Thanks Paul.

Oddly, my code works properly again without change after I reloaded PB and recompiled.

Appreciate the help.

Terry
Post Reply