隐藏垂直滚动条/同步顶部项目与 Scrollable = false

发布于 2024-12-02 05:25:07 字数 726 浏览 5 评论 0原文

我正在尝试同步 2 个列表视图,以便其中一个实际上是一列的“冻结窗格”(想想 excel 冻结标题)。

但是,我在滚动时很难使顶部项目同步。我需要隐藏标题列表视图上的垂直和水平滚动条,这可以通过将 Scrollable 设置为 false 来实现。虽然这似乎禁用了“EnsureVisible”和“TopItem”功能?

我已经拦截了主列表视图上的滚动条消息,所以我知道何时滚动,只是由于某种原因我无法更新标题列表视图上的顶部项目以匹配。

我用于更新标题列表视图的代码如下:

//On vertical scroll click...
  if (e.Type == ScrollEventType.EndScroll)
  {
    int index = lvwHeader.FindItemWithText(lvwSource.TopItem.Text).Index;

    ListViewItem item = lvwHeader.Items[index];
    lvwHeader.TopItem = item;

    System.Diagnostics.Debug.WriteLine(lvwHeader.TopItem.Text + " - " + lvwSource.TopItem.Text);
  }

所以我想知道是否有另一种方法可以强制标题列表视图在 Scrollable = false 时将项目设置为 topitem,或者是否有更好的方法来解决此问题?

非常感谢

I'm trying to sync up 2 list views, so that one of them is effectively a 'freeze pane' of one column (think excel freeze-headers).

However, I am having difficulty in getting the top items to sync up when scrolling. I need to hide the vertical and horizontal scrollbars on the header-list view, which can be achieved by setting Scrollable to false. Though this seems to disable the 'EnsureVisible' and 'TopItem' functionality?

I have intercepted the scroll bar messages on the master listview, so I know when that is being scrolled, just for some reason I'm unable to update the top item on the header listview to match up.

The code I have for updating the header listview is as follows:

//On vertical scroll click...
  if (e.Type == ScrollEventType.EndScroll)
  {
    int index = lvwHeader.FindItemWithText(lvwSource.TopItem.Text).Index;

    ListViewItem item = lvwHeader.Items[index];
    lvwHeader.TopItem = item;

    System.Diagnostics.Debug.WriteLine(lvwHeader.TopItem.Text + " - " + lvwSource.TopItem.Text);
  }

So I was wondering if there was another way to force the header listview to set an item as the topitem whilst Scrollable = false, or if there was a better way to approach this?

Many thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文