Page 1 of 1

Set ListView height to X items?

Posted: Sat Jan 28, 2017 8:50 am
by Dude
Is there a way I can set a ListViewGadget's height to be exactly 10 items high, no matter which font is in use? Basically I just need to know how to get a single item's height so I can multiply it. Thanks. I think it's to do with #LVM_GETITEMRECT but I'm not sure how to apply it.

Re: Set ListView height to X items?

Posted: Sat Jan 28, 2017 9:35 am
by netmaestro
LVM_xxx messages are incompatible with PB's ListvewGadget. That's because, despite their name, they aren't MS Listview controls at all. They are actually ListBox controls that respond to LB_xxx messages. See if this slight modification of the PB sample code for the ListviewGadget is of some help:

Code: Select all

If OpenWindow(0, 0, 0, 270, 480, "ListViewGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
   ListViewGadget(0, 10, 10, 250, 120)
   Debug SendMessage_(GadgetID(0), #LB_GETITEMHEIGHT,0,0)
   SetGadgetFont(0, LoadFont(0, "arial", 24))
   a = SendMessage_(GadgetID(0), #LB_GETITEMHEIGHT,0,0)
   Debug a 
   FreeGadget(0)
   ListViewGadget(0, 10, 10, 250, 10*a)
   
   SetGadgetFont(0, LoadFont(0, "arial", 24))
    For i = 1 To 10
      AddGadgetItem (0, -1, "Item " + Str(i) + " of the Listview") ; define listview content
    Next
    SetGadgetState(0, 0) ; set (beginning with 0) the tenth item as the active one
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
  

Re: Set ListView height to X items?

Posted: Sat Jan 28, 2017 10:51 am
by Dude
Thanks netmaestro, it's always so nice to get your quick and helpful replies. :)

For my project, however, I had to amend it like the following to work perfectly. Not sure where the 0.4 calculation comes from, but it's needed.

Code: Select all

If OpenWindow(0, 0, 0, 270, 400, "ListViewGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListViewGadget(0, 10, 10, 250, 0)
  num = 10
  For i = 1 To num
    AddGadgetItem (0, -1, "Item " + Str(i) + " of the Listview")
  Next
  h = SendMessage_(GadgetID(0), #LB_GETITEMHEIGHT, 0, 0)
  ResizeGadget(0, #PB_Ignore, #PB_Ignore, #PB_Ignore, h * (num + 0.4) )
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

Re: Set ListView height to X items?

Posted: Tue Jan 31, 2017 8:17 pm
by Lord
Hello!

Is there also a way to get for a ListIconGadget the heights of an item?

Re: Set ListView height to X items?

Posted: Wed Feb 01, 2017 11:38 am
by Shardik
Lord wrote:Is there also a way to get for a ListIconGadget the heights of an item?
Please be aware that your question is offtopic because this thread deals only with the ListViewGadget. In Linux and MacOS ListIconGadget and ListViewGadget have the same API basis but not on Windows as netmaestro already explained:
netmaestro wrote:LVM_xxx messages are incompatible with PB's ListvewGadget. That's because, despite their name, they aren't MS Listview controls at all. They are actually ListBox controls that respond to LB_xxx messages.
For ListIconGadgets I posted already a cross-platform example that demonstrates how to get and set the height of a row.

Re: Set ListView height to X items?

Posted: Thu Jun 01, 2017 3:38 pm
by Xanos
If anybody is interested. The Linux (GTK) version of

Code: Select all

h = SendMessage_(GadgetID(0), #LB_GETITEMHEIGHT, 0, 0)
ist the following:

Code: Select all

Procedure getRowHeight(gadget)
  Protected height, yOffset
  Protected *tree, *tree_column
  *tree = GadgetID(gadget)
  
  ; https://developer.gnome.org/gtk3/stable/GtkTreeView.html#gtk-tree-view-get-column
  *tree_column = gtk_tree_view_get_column_(*tree, 0)
  
  ; https://developer.gnome.org/gtk3/stable/GtkTreeViewColumn.html#gtk-tree-view-column-cell-get-size
  gtk_tree_view_column_cell_get_size_(*tree_column, #Null, #Null, @yOffset, #Null, @height)
  
  ProcedureReturn height
EndProcedure