Mandatory VSCROLL on listview..
Posted: Mon Aug 09, 2004 10:09 pm
How do I make a mandatory VSCROLL bar on a LISTVIEW when there
aren't enough items to make it popup?
aren't enough items to make it popup?
http://www.purebasic.com
https://www.purebasic.fr/english/
The code below isn't pretty but it works here on WinXPhome with PB 3.91. The only drawback is it also adds a HSCROLL bar as well. You can remove the HSCROLL bar by uncommenting 3 lines in the code. This does not free up the HSCROLL rect, so you are left with a little dead area. Good place for a button or some maybe some textmsdn Platform SDK wrote:To create a list box by using the CreateWindow or CreateWindowEx function, use the LISTBOX class, appropriate window style constants, and the following style constants to define the list box. After the control has been created, these styles cannot be modified, except as noted.
LBS_DISABLENOSCROLL
Shows a disabled vertical scroll bar for the list box when the box does not contain enough items to scroll. If you do not specify this style, the scroll bar is hidden when the list box does not contain enough items.
Code: Select all
If OpenWindow(0, 0, 0, 250, 170, #PB_Window_SystemMenu | #PB_Window_ScreenCentered,"ListView Forced VScroll")
CreateGadgetList(WindowID(0))
ListViewGadget(0, 10, 10, 230, 130, #LBS_DISABLENOSCROLL)
; uncomment the next 3 lines remove the HSCROLL
;style = GetWindowLong_(GadgetID(0), #GWL_STYLE)
;newstyle = style &(~#WS_HSCROLL)
;SetWindowLong_(GadgetID(0), #GWL_STYLE, newstyle)
For i=1 To 5
AddGadgetItem (0, -1, "Item number " + Str(i))
Next
SetGadgetState(0, 3)
EndIf
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
End
I uncommented the section you mentioned.. maybe its in that.. I wouldSparkie wrote:That's odd. I've run the code over a dozen times on WinXPhome and my cpu hasn't suffered from any side effects at all.
Code: Select all
If OpenWindow(0, 0, 0, 250, 170, #PB_Window_SystemMenu | #PB_Window_ScreenCentered,"ListView Forced VScroll")
CreateGadgetList(WindowID(0))
ListViewGadget(0, 10, 10, 230, 130, #LBS_DISABLENOSCROLL)
; uncomment the next 3 lines remove the HSCROLL
style = GetWindowLong_(GadgetID(0), #GWL_STYLE)
newstyle = style &(~#WS_HSCROLL)
SetWindowLong_(GadgetID(0), #GWL_STYLE, newstyle)
ResizeGadget(0,10,10,230,129) ; Resize to get rid of "dead spot"
For i=1 To 5
AddGadgetItem (0, -1, "Item number " + Str(i))
Next
SetGadgetState(0, 3)
EndIf
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
End
Code: Select all
ResizeGadget(0,10,10,230,129) ; Resize to get rid of "dead spot"
ResizeGadget(0,10,10,230,130)
Code: Select all
; English Forum: http://jconserv.net/purebasic/viewtopic.php?t=12053
; Authors: Sparkie, deadmoap
; Date: August 10, 2004
;
; This is an example of how to use a VSCROLL in a listview when you
; don't have enough items to make it show up.
;
; Also, very important, because of forcing the VSCROLL, the HSCROLL
; shows up, just resize the listview and the HSCROLL will go away.
If OpenWindow(0, 0, 0, 250, 170, #PB_Window_SystemMenu | #PB_Window_ScreenCentered,"ListView Forced VScroll")
CreateGadgetList(WindowID(0))
ListViewGadget(0, 10, 10, 230, 130, #LBS_DISABLENOSCROLL)
; uncomment the next 3 lines remove the HSCROLL
style = GetWindowLong_(GadgetID(0), #GWL_STYLE)
newstyle = style &(~#WS_HSCROLL)
SetWindowLong_(GadgetID(0), #GWL_STYLE, newstyle)
ResizeGadget(0,10,10,230,129) ; Resize to get rid of "dead spot"
ResizeGadget(0,10,10,230,130)
For i=1 To 5
AddGadgetItem (0, -1, "Item number " + Str(i))
Next
SetGadgetState(0, 3)
EndIf
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
End