Click to See Complete Forum and Search --> : Problems with ListBox!!!


AScomp
December 19th, 1999, 04:42 AM
Hello,

my entries in List1 (ListBox) are to long, so they cannot be displayed right. how can I create a horizontal scrollbar or let appear the unvisible part one line down?

Thanks a lot for your help!!!

AScomp

Jean Spector
December 19th, 1999, 10:15 AM
You can use a picturebox with hidden method .Print - something like Picture1.Print List1.List(Index).
If it looks too complicated - let me know and I'll send you an example - I have it at home already done (met the same problem some day)

Jean Spector
Tech Support Team Leader, CET
mage@lycosmail.com
(in VB from 11/1999)

Chris Eastwood
December 20th, 1999, 04:15 AM
You can use the following code to find out the max-length of your widest item in the listbox and then set a Horizontal scrollbar in the listbox :

Create a new project with a form (FORM1) a listbox (LIST1) and a button (Command1) and paste in the following code :


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 Const LB_SETHORIZONTALEXTENT = &H194
'
private Sub Command1_Click()
Dim lMaxLen as Long
Dim lCount as Long
'
for lCount = 0 to List1.ListCount - 1
If TextWidth(List1.List(lCount)) > lMaxLen then
lMaxLen = TextWidth(List1.List(lCount))
End If
next
'
lMaxLen = lMaxLen / Screen.TwipsPerPixelX ' if twips change to pixels
SendMessage List1.hwnd, LB_SETHORIZONTALEXTENT, lMaxLen, 0&
'
End Sub





Chris Eastwood

CodeGuru - the website for developers
http://codeguru.developer.com/vb