Mandatory VSCROLL on listview..
- NoahPhense
- Addict
- Posts: 1999
- Joined: Thu Oct 16, 2003 8:30 pm
- Location: North Florida
Mandatory VSCROLL on listview..
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?
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
Last edited by Sparkie on Tue Aug 10, 2004 2:42 am, edited 1 time in total.
What goes around comes around.
PB 5.21 LTS (x86) - Windows 8.1
PB 5.21 LTS (x86) - Windows 8.1
- NoahPhense
- Addict
- Posts: 1999
- Joined: Thu Oct 16, 2003 8:30 pm
- Location: North Florida
- NoahPhense
- Addict
- Posts: 1999
- Joined: Thu Oct 16, 2003 8:30 pm
- Location: North Florida
I just ran the code with the 3 lines uncommented and still no problems here. I even ran 5 instances at once and left them running for a few minutes. No cpu usage during runtime and no crash.
Don't know what to say other than I'm sorry for sending the blues you way.
Don't know what to say other than I'm sorry for sending the blues you way.

What goes around comes around.
PB 5.21 LTS (x86) - Windows 8.1
PB 5.21 LTS (x86) - Windows 8.1
- NoahPhense
- Addict
- Posts: 1999
- Joined: Thu Oct 16, 2003 8:30 pm
- Location: North Florida
Apparently, resizing the gadget gets rid of the "dead" spot at the bottom where the HSCROLL was.
Although it may seem more logical to resize it to 230,130 (original size), but the Win32 API doesn't really resize it unless you made a change to its proportions.
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
- NoahPhense
- Addict
- Posts: 1999
- Joined: Thu Oct 16, 2003 8:30 pm
- Location: North Florida
Ok Sparkie and deadmoap, I've decided to use this method. Thanks for
the help, this is good work.
@deadmoap
I just do another resize to go back to normal.. 
- np
the help, this is good work.
@deadmoap
Code: Select all
ResizeGadget(0,10,10,230,129) ; Resize to get rid of "dead spot"
ResizeGadget(0,10,10,230,130)

- np
- NoahPhense
- Addict
- Posts: 1999
- Joined: Thu Oct 16, 2003 8:30 pm
- Location: North Florida
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