Click here to Skip to main content
14,327,460 members
Rate this:
Please Sign up or sign in to vote.
See more:
Is there a way where we can Sync scroll Label, TextBox or RichTextBox with ListBox ScrollBar?

ScrollBar should be visible only for ListBox and (Label, TextBox or RichTextBox should not have any scollbar)

I've mentioned Label, TextBox or RichTextBox, anyone could work for me, whichever is compatible to sync scroll with ListBox.

What I have tried:

I tried 2 RichTextBox sync but thats not what I'm looking for, though, I've also tried 2 ListBox Scroll and I've Hide 1 ScrollBar Scroller but that is slow and not scrolling together, there's a delay of some milliseconds.
Updated 1-Nov-17 6:32am

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

I got this working for a ListBox and a RichTextBox but only one way... Meaning that scrolling the RTB will scroll the LB but not the opposite
Here is the code... Put it in the VScroll function of the RTB
Dim lineNumber As Integer = 0
lineNumber is a global variable...
Dim firstVisibleChar As Integer = RichTextBox1.GetCharIndexFromPosition(New Point(0, 0))
lineNumber = RichTextBox1.GetLineFromCharIndex(firstVisibleChar)
ListBox1.TopIndex = lineNumber

I know we can simplify this code more, but I've made it a bit longer so that anyone can easily understand it...
Shaikh Javed Aryan 6-Nov-17 9:59am
This is great but I wanted Listbox to RichTextBox
Mrunal Sonawane 6-Nov-17 11:19am
But you can try one thing... hide the scrollbar of ListBox and put the RTB on the right hand side so that you have only one scrollbar visible.

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100