[英]Datagridview ScrollBar Looses it's focus after binding reset
I have a DataGridView, which I need to update the content every 3 seconds. 我有一个DataGridView,我需要每3秒更新一次内容。 I am able to save the DGV position with this code:
我可以使用以下代码保存DGV位置:
private void UpdateBindings()
{
int _ScrollPosition = MonitorGridView.FirstDisplayedScrollingRowIndex;
_BS.ResetBindings(false); // _BS = BindingSource
if (_ScrollPosition > -1)
{
MonitorGridView.FirstDisplayedScrollingRowIndex = _ScrollPosition;
}
}
This code works perfect, however, the ONLY problem I am facing is that I lose the FOCUS on my scrollbar after every reset. 这段代码可以完美地工作,但是,我面临的唯一问题是每次重置后,滚动条上的FOCUS都丢失了。 Let's say I am scrolling to the bottom, and it updates, I need to regrab the scrollbar again.
假设我要滚动到底部,并且它会更新,我需要再次重新滚动滚动条。 This is very annoying.
这很烦人。
My question is exactly same as this one: Scrollbar loses focus when datagridview refreshs its content 我的问题与这一问题完全相同: 当datagridview刷新其内容时,滚动条失去焦点
However, I am not able to find the answer or figure out a way for me to solve this. 但是,我找不到答案或想办法解决这个问题。
Can anyone please point me to the correct way? 有人可以指出正确的方法吗? Thanks
谢谢
Solved the problem by creating a new vScrollBar and programatically changing the current row value of DataGridView. 通过创建一个新的vScrollBar并以编程方式更改DataGridView的当前行值来解决该问题。
private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
if (e.NewValue > -1 && e.NewValue < MonitorGridView.Rows.Count)
{
MonitorGridView.FirstDisplayedScrollingRowIndex = e.NewValue;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.