locked
Synchronize datagrid Scroll vertical

    Question

  • Hi,

    I am having two datagrid side by side. I want to vertically scroll both datagrid at a time ie synchronize both scroll bar movement vertically.

     kindly give code sample to do so.
    Thursday, January 21, 2010 5:03 AM

Answers

  • Hi,

    Do you mean datagridview control?
    Please try the code below:

            private void dataGridView1_Scroll(object sender, ScrollEventArgs e)

            {

                this.dataGridView2.FirstDisplayedScrollingRowIndex = this.dataGridView1.FirstDisplayedScrollingRowIndex;

                this.dataGridView2.HorizontalScrollingOffset = this.dataGridView1.HorizontalScrollingOffset;

            }

     

            private void dataGridView2_Scroll(object sender, ScrollEventArgs e)

            {

                this.dataGridView1.FirstDisplayedScrollingRowIndex = this.dataGridView2.FirstDisplayedScrollingRowIndex;

                this.dataGridView1.HorizontalScrollingOffset = this.dataGridView2.HorizontalScrollingOffset;

            }

    For more info , please take a look at the thread:
    http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/ef832fa4-b2bd-4d38-8bd2-2dae37557554/

    Harry


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Benita Blas Monday, January 25, 2010 11:44 AM
    Monday, January 25, 2010 8:47 AM