-
Aug 30th, 2014, 06:05 PM
#1
Thread Starter
New Member
Autoscrolling to bottom of datagridview
My application adds rows to a datagridview, but when it adds rows past the bottom of the visible datagridview on the form I want the grid to scroll up so that the last entry is always shown and the user doesn't have to manually scroll to the bottom.
-
Aug 30th, 2014, 08:30 PM
#2
Re: Autoscrolling to bottom of datagridview
Code:
Private Sub DataGridView1_RowsAdded(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowsAddedEventArgs) Handles DataGridView1.RowsAdded
DataGridView1.FirstDisplayedScrollingRowIndex = e.RowIndex + e.RowCount - 1
End Sub
-
Aug 31st, 2014, 02:40 AM
#3
Re: Autoscrolling to bottom of datagridview
The grid can't actually scroll past the last row being at the bottom of the grid so you can simply specify the last row as the first displayed row and the grid will just scroll as far as it can.
Code:
Me.DataGridView1.FirstDisplayedScrollingRowIndex = Me.DataGridView1.RowCount - 1
-
Aug 31st, 2014, 10:14 AM
#4
Re: Autoscrolling to bottom of datagridview
Originally Posted by jmcilhinney
The grid can't actually scroll past the last row being at the bottom of the grid so you can simply specify the last row as the first displayed row and the grid will just scroll as far as it can.
Code:
Me.DataGridView1.FirstDisplayedScrollingRowIndex = Me.DataGridView1.RowCount - 1
As the OP has phrased the question, this is probably valid. However it presumes that the added row will be positioned as the last displayed row. If the control is subject to sorting this may not be the case. Using the event with its supplied data will work in all cases.
-
Aug 31st, 2014, 09:34 PM
#5
Re: Autoscrolling to bottom of datagridview
Originally Posted by TnTinMN
As the OP has phrased the question, this is probably valid. However it presumes that the added row will be positioned as the last displayed row. If the control is subject to sorting this may not be the case. Using the event with its supplied data will work in all cases.
Valid point.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|