Click here to Skip to main content
15,888,733 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Trying to control a listbox scrollbar using values generated from a trackbar control
Posted
Comments
CHill60 11-Jun-15 15:33pm    
Try posting your code and explaining what the problem is
[no name] 12-Jun-15 6:39am    
Thanks for reply. Will extract code I'm using and post it later.

1 solution

VB
Private Sub ScrollListBox(box As ListBox, tBar As TrackBar)
     If box Is Nothing OrElse tBar Is Nothing OrElse box.Items.Count < (box.Height \ box.ItemHeight) Then
         Return
     End If
     box.SuspendLayout()
     Dim pct = tBar.Value / (tBar.Maximum - tBar.Minimum)
     Dim pageItems = box.Height \ box.ItemHeight
     Dim lbIndex = Math.Max(0, CInt((pct * box.Items.Count) - (pageItems / 2)))
     box.TopIndex = lbIndex
     box.ResumeLayout()
 End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900