【问题标题】:Manage two or more frames datagridview with one scrollbar in c#?在c#中使用一个滚动条管理两个或多个帧datagridview?
【发布时间】:2011-12-06 08:25:20
【问题描述】:

首先,对不起我的英语不好 - 我是西班牙人。 我正在编写一个应用程序来获得我女朋友学校的资格。我将应用程序分为两部分,TableLayoutPanelDataGridView 用于获取 Access 数据库的学生的姓名。而TableLayoutPanel 的另一部分,我有学生评估的笔记,使用相同的数据库但另一个表。我想要的是,用一个滚动条来移动两个或多个datagridview一次移动。

有可能吗? 应用截图:http://img21.imageshack.us/img21/6237/colegest.jpg 谢谢。

【问题讨论】:

    标签: c# datagridview scrollbar frame tablelayoutpanel


    【解决方案1】:

    您可以在一个 DataGridView 中捕获 Scroll 事件,然后设置另一个 DataGridView 的 FirstDisplayedScrollingRowIndex 属性,因此,假设“源”数据网格名为 dataGridSource,另一个名为 dataGridTarget,并且两者具有相同的行数,你可以这样写:

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

    【讨论】:

    • 如果你喜欢这个答案,请点击接受——这会将这个主题标记为已回答(也给我一些声誉)。谢谢。
    猜你喜欢
    • 2016-01-10
    • 1970-01-01
    • 2017-09-04
    • 2020-07-03
    • 1970-01-01
    • 2017-07-31
    • 1970-01-01
    相关资源
    最近更新 更多