Reputation: 139
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.
Here is the image:
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?
Upvotes: 3
Views: 224
Reputation: 32223
See whether the cells scroll behavior modified in this manner can be of use in your context.
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's bounds will expand automatically.
Also, check the cutOverflow
parameter of the GetCellDisplayRectangle()
method for a slightly different behavior when considering a Cell
bounds extent.
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
Upvotes: 3