【问题标题】:How to move two scrollbars simultaneously如何同时移动两个滚动条
【发布时间】:2021-10-07 03:07:53
【问题描述】:

我有 2 个DataGridViews。假设它们始终具有相同数量的具有相同高度的行。每当我在其中一个上移动ScrollBar 时(都带有MouseWheelScrollBar),我想同时移动另一个(我只想在垂直的ScrollBars 上执行此操作)。我怎样才能做到这一点?

【问题讨论】:

  • 那他们为什么不只是一个datagridview呢?
  • 同步他们的FirstDisplayedScrollingRowIndex属性
  • @Caius Jard 这是客户的特定要求。同步它们的属性是什么意思?
  • DGV 有一个 FirstDisplayedScrollingRowIndex 属性,它可以告诉您或允许您设置首先显示哪一行。如果您滚动一个 DGV(例如,现在将第 10 行显示为其第一行),您可以获得哪个索引是第一个(例如 10)并设置另一个 DGV,使其显示相同的第一行(例如 10)

标签: c# winforms


【解决方案1】:

@Caius Jard 告诉你要做的是:

首先,创建两个DataGridView,然后在Scroll事件上同步FirstDisplayedScrollingRowIndex

dataGridView1.Scroll += DataGridView1OnScroll;

private void DataGridView1OnScroll(object sender, ScrollEventArgs scrollEventArgs) {
    dataGridView2.FirstDisplayedScrollingRowIndex = dataGridView1.FirstDisplayedScrollingRowIndex;
}

观察

我尝试使用WndProc 来同步两个DataGrid,using this,但它不起作用……嗯,它可以使用鼠标滚轮,但不能通过拖动滚动条。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-24
    • 2012-08-15
    • 1970-01-01
    • 1970-01-01
    • 2014-07-23
    • 2020-10-15
    相关资源
    最近更新 更多