停止自动滚动数据网格视图? [英] Stop datagridview from autoscrolling?

查看:25
本文介绍了停止自动滚动数据网格视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个虚拟模式的 datagridview,可以快速填充数据.添加新行会自动将 datagridview 滚动到底部.无论如何要禁用此功能而不禁用滚动条?当项目被添加到网格时,用户应该仍然能够自由滚动,而不会吸附到底部.

I have a datagridview in virtual mode that gets quickly populated with data. adding a new row auto scrolls the datagridview to the bottom. Is there anyway to disable this functionality without disabling scroll bars? The user should still be able to scroll around freely as items are added to the grid without it snapping to the bottom.

全行选择和多选都已启用.

Full row select and multi-select are both enabled.

推荐答案

这对我有用.答案是保存当前显示的行索引,然后在刷新 datgridview 后重置为该索引.在我的情况下,datagridview 处于虚拟模式:

Here is what worked for me. The answer is to save the current displayed row index and than reset to that index after the datgridview is refreshed. In my case the datagridview is in virtual mode:

        Dim saveRow As Integer = 0
        If DataGridView1.Rows.Count > 0 Then
            saveRow = DataGridView1.FirstDisplayedCell.RowIndex
        End If

        DataGridView1.RowCount = fullitem.Count + 1

        If saveRow < DataGridView1.Rows.Count Then
            DataGridView1.FirstDisplayedScrollingRowIndex = saveRow
        End If

这篇关于停止自动滚动数据网格视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆