I have a DataGridView, which I need to update the content every 3 seconds. I am able to save the DGV position with this code:
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. 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
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.
private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
if (e.NewValue > -1 && e.NewValue < MonitorGridView.Rows.Count)
{
MonitorGridView.FirstDisplayedScrollingRowIndex = e.NewValue;
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments