问题描述
我有一个问题,其中DataGidView的最后一列太长,您需要使用滚动条来显示该列的其余部分.
但是,当我键入文本时,键入时它不会自动滚动.
I have this problem where the last column in DataGidView is too long and you need to use scroll bar to go to show the rest of that column.
But when I type a text, it will not auto scroll while typing.
我想要的是我想在键入时自动滚动滚动条,以便用户在键入时不必使用滚动条.
What I want is that I want to auto scroll the scroll bar when typing so that the user will not have to use the scroll bar while typing.
这是图片:
如您所见,最后一列是备忘录.
当我在备忘录中键入文本时,它将不会自动滚动.如何实现呢?
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?
推荐答案
查看以此方式修改的单元格滚动行为是否可以在您的上下文中使用.
See whether the cells scroll behaviour modified in this manner can be of use in your context.
输入的 Cell
使用 DataGridView.GetCellDisplayRectangle(),并且如果它的 Right
位置超出 DataGridView
范围,当前单元格之前的 Cell
范围设置为 FirstDisplayedCell
.
这应确保输入 Cell
时始终将其滚动到视图中.
在编辑模式下,单元格
范围将自动扩展.
The entered Cell
is measured with DataGridView.GetCellDisplayRectangle() and, if it's Right
position falls beyond the DataGridView
bounds, the Cell
before the current is set as the FirstDisplayedCell
.
This should ensure that a Cell
is always scrolled into view when entered.
When in edit mode, the Cell
bounds will expand automatically.
此外,在考虑 Cell
边界范围时,请检查 GetCellDisplayRectangle()
方法的 cutOverflow
参数是否有明显不同的行为.
Also, check the cutOverflow
parameter of the GetCellDisplayRectangle()
method for a slighltly different behaviour when considering a Cell
bounds extent.
Private Sub DataGridView1_CellEnter(sender As Object, e As DataGridViewCellEventArgs)
Dim CellArea As Rectangle = 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
这篇关于键入时自动滚动DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!