隐藏垂直滚动条/同步顶部项目与 Scrollable = false
我正在尝试同步 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论