Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Linking scroll operations of two RTBs

Status
Not open for further replies.

0ddball

Technical User
Nov 6, 2003
208
GB
Hi hi hi,

I need to link the vertical scroll operations for two rich text boxes (already extended to a custom control so I have access to the protected members).

I found this method in a post from March '03 but I can't seem to port the code from a DataGrid to my Rich Text Boxes.

crystalruchs said:
You are right that value property makes the scroll bar to change its position, but the problem is it doesn't scroll the grid also.
Following solution works for me

Create a derieved class, since HorizScrollBar property and GridHScrolled
method are protected.
Code:
public class MyGrid:System.Windows.Forms.DataGrid
{    
    public int getHorizScrollBarX()
    {
        return this.HorizScrollBar.Value;
    }
    public void setHorizScrollBarX(int x)
    {
        //this.HorizScrollBar.Value = x;

        this.GridHScrolled(this, new ScrollEventArgs(System.Windows.Forms.ScrollEventType.LargeIncrement, x));
    }

}
Set both the datagrids to be of type MyGrid. In the scroll event just
write.
Code:
private void dataGrid1_Scroll(object sender, System.EventArgs e)
{
    int x = dataGrid1.getHorizScrollBarX();
    dataGrid2.setHorizScrollBarX(x);
}
I need the first box (tbAy) to scroll to the same location as the second (tbBee).

tbAy always has exactly the same number of lines as tbBee - the data displayed is related.


Yet another unchecked rambling brought to you by:
Oddball
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top