键入时自动滚动 DataGridView

2024-06-18

我遇到这个问题,DataGridView 中的最后一列太长,您需要使用滚动条来显示该列的其余部分。
但是当我输入文本时,它不会在输入时自动滚动。


我想要的是,我想在打字时自动滚动滚动条,以便用户在打字时不必使用滚动条。

这是图像:

The datagridview As you can see the last column is memoranda.
When I type a text in memoranda it will not auto scroll. How to achieve this?


查看以这种方式修改的单元格滚动行为是否可以在您的上下文中使用。

输入的单元格通过测量DataGridView.GetCellDisplayRectangle() https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.datagridview.getcelldisplayrectangle并且,如果是Right位置超出了DataGridView界限,即Cell在电流被设置为之前第一个显示单元格 https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.datagridview.firstdisplayedcell.
这应该确保单元格在输入时始终滚动到视图中。
当处于编辑模式时,单元格的边界将自动扩展。

另外,请检查cutOverflow的参数GetCellDisplayRectangle()方法在考虑时略有不同的行为Cell界限范围。

Private Sub DataGridView1_CellEnter(sender As Object, e As DataGridViewCellEventArgs)
    Dim cellArea = DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, False)
    If cellArea.Right > DataGridView1.Width AndAlso e.ColumnIndex > 0 Then
        DataGridView1.FirstDisplayedCell = DataGridView1(e.ColumnIndex - 1, e.RowIndex)
    End If
End Sub
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

键入时自动滚动 DataGridView 的相关文章