I have a DataGridView on a form which has a refresh button on it for re-reading the data in the DataGridView. I would like for the scroll position of the DataGridView to be returned to where it was before re-reading the data rather than positioning the scrolling to the top left. I tried the following code and it is an improvement over setting the scroll to the top left but it still causes some noticeable shift in the DGV's position:
I also tried:Code:Dim ptCurrentCell As Point ptCurrentCell = Me.ReportDataGridView.CurrentCellAddress ReportDataGridView.DataSource = dt ReportDataGridView.CurrentCell = Me.ReportDataGridView.Rows(ptCurrentCell.Y).Cells(ptCurrentCell.X)
Again, a noticeable shift. Is there any way I can get it to reset if not exactly then close to the pre-refeshed position?Code:Dim iHorScroll As Integer Dim iVerScroll As Integer iHorScroll = ReportDataGridView.FirstDisplayedScrollingRowIndex iVerScroll = ReportDataGridView.FirstDisplayedScrollingColumnIndex ReportDataGridView.DataSource = dt ReportDataGridView.FirstDisplayedScrollingColumnIndex = iHorScroll ReportDataGridView.FirstDisplayedScrollingRowIndex = iVerScroll




Reply With Quote