Set ListView height to X items?
Set ListView height to X items?
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.
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Set ListView height to X items?
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
BERESHEIT
Re: Set ListView height to X items?
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.

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?
Hello!
Is there also a way to get for a ListIconGadget the heights of an item?
Is there also a way to get for a ListIconGadget the heights of an item?

Re: Set ListView height to X items?
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:Lord wrote:Is there also a way to get for a ListIconGadget the heights of an item?
For ListIconGadgets I posted already a cross-platform example that demonstrates how to get and set the height of a row.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.
Re: Set ListView height to X items?
If anybody is interested. The Linux (GTK) version of ist the following:
Code: Select all
h = SendMessage_(GadgetID(0), #LB_GETITEMHEIGHT, 0, 0)
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
Programming on Windows 10 Pro / Windows 7 Enterprise / Linux Mint 19 / Manjaro Linux with PB 5, Python 3 and Go