[RESOLVED] Problem moving listbox horizontal lisbox scroller to the right
Hi all i put a horizantal scroller for mylistbox but unfortuntally i can not use it sicne i have long data in my listbox and i can not move the tab for the horizantal listbox since the with of is big enought that does not allow any movment to right side!! Even if i try to make my listbox width big still i face problem. Is there a way to make the size of scroller tab smaller so i can move it to the right side ? I hope some one help me here.Thanks
VB Code:
Private Declare Function ShowScrollBar Lib "user32" (ByVal hwnd As Long, ByVal wBar As Long, _
ByVal bShow As Long) As Long
Private Const SB_HORIZONTAL = 0
Re: Problem moving listbox horizontal lisbox scroller to the right
By default the VB Listbox does not od Horizontal scrolling. You need to set the Columns property greater than 1 - but then Vertical scrolling is not supported.
Anyways, to get Horizontal and Vertical scrolling set the "Horizontal Extent" (aka Right Margin) of the ListBox (default is the Width of the control).
VB Code:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const LB_SETHORIZONTALEXTENT = &H194
'set the right margin to 3 times the width of the control
SendMessage List1.hwnd, LB_SETHORIZONTALEXTENT, ScaleX(List1.Width * 3, Me.ScaleMode, vbPixels), 0
You can then use the ShowScrollBar API.
Re: Problem moving listbox horizontal lisbox scroller to the right
Thank u for u reply.
I want to go with non api method and i can not find the place to changes u mentioned .I can not find horizontal extent!!
Quote:
Horizontal and Vertical scrolling set the "Horizontal Extent" (aka Right Margin) of the ListBox (default is the Width of the control).
Re: Problem moving listbox horizontal lisbox scroller to the right
You cannot change the Horizontal Extent on a VB ListBox without using the API method.
Re: Problem moving listbox horizontal lisbox scroller to the right
Quote:
Originally Posted by brucevde
You cannot change the Horizontal Extent on a VB ListBox without using the API method.
I put your code in the top of my project and i get this error:
Code:
Compile error
Invalid outside procedure!
and pointing at bold part
Code:
SendMessage List1.hwnd, LB_SETHORIZONTALEXTENT, ScaleX(List1.Width * 3, Me.ScaleMode, vbPixels), 0
Re: Problem moving listbox horizontal lisbox scroller to the right
That line is a statement and needs to be put into a procedure, like Form_Load
VB Code:
'in a form that contains a listbox called List1
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function ShowScrollBar Lib "user32" (ByVal hwnd As Long, ByVal wBar As Long, _
ByVal bShow As Long) As Long
Private Const SB_HORIZONTAL = 0
Private Const LB_SETHORIZONTALEXTENT = &H194
Private Sub Form_Load()
List1.AddItem "set the right margin to 3 times the width of the control"
SendMessage List1.hwnd, LB_SETHORIZONTALEXTENT, ScaleX(List1.Width * 3, Me.ScaleMode, vbPixels), 0
ShowScrollBar List1.hwnd, SB_HORIZONTAL, 1
End Sub
Re: Problem moving listbox horizontal lisbox scroller to the right
I get this error now :
Code:
Compile error:
Ambiguouse naem detected :ShowScrollBar
pointing at this line :
VB Code:
Private Declare Function ShowScrollBar Lib "user32" (ByVal hwnd As Long, ByVal wBar As Long, _
ByVal bShow As Long) As Long
Re: Problem moving listbox horizontal lisbox scroller to the right
You have 2 functions and/or procedures called ShowScrollBar in the same module.
Re: Problem moving listbox horizontal lisbox scroller to the right
Quote:
Originally Posted by brucevde
You have 2 functions and/or procedures called ShowScrollBar in the same module.
thanks man it worked. Now i can move the horizantal scroll bar to the right easily:-))