简体   繁体   中英

Manage two or more frames datagridview with one scrollbar in c#?

In the first place, sorry for my bad english - I'm Spanish. I'm programming an application to take the qualifications of my girlfriend's school. I have divided the application into two parts by a TableLayoutPanel with a DataGridView for the names of the students who take an Access database. And the other part of the TableLayoutPanel , I have the notes of student assessments with the same database but another's tables. What I want, is that with a single scrollbar to move two or more datagridview to move at once.

Is it possible? App screenshot: http://img21.imageshack.us/img21/6237/colegest.jpg Thanks.

You could capture the Scroll event in one DataGridView and then set the FirstDisplayedScrollingRowIndex property of the other one, thus, assuming the "source" data grid is named dataGridSource and the other one dataGridTarget, and that both have the same number of rows, you can write:

    private void dataGridSource_Scroll(object sender, ScrollEventArgs e)
    {
        if(e.ScrollOrientation == ScrollOrientation.VerticalScroll)
        {
            int i = dgvLog.FirstDisplayedScrollingRowIndex ;
            dataGridTarget.FirstDisplayedScrollingRowIndex  = i;
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM