See a row that is selected if it's below the the visible rows

I'm having a problem when the number of rows in my datagrid is more then the number of rows that are visible. When I load the form, i want it to automatically move down to the last row. I can move the arrow and i can highlight the row, but i can't move the down to bottom, i have to scroll down to see it. how can i see it without scrolling down?
thanks to anyone who can help
[382 byte] By [codefund.com] at [2007-12-16]
# 1
Well, "scroll" can have multiple interpretations. If you simply want to leave the first row selected, but scroll to the bottom, I'm not finding a simple solution (although, there may be one I'm just not aware of). On the other hand, if you can live with selecting the final row (which forces it to be displayed), you could add code like this to the code where you set the grid's DataSource:

DataGrid1.DataSource = ds.Tables(0)
DataGrid1.CurrentRowIndex = ds.Tables(0).Rows.Count - 1

or something like that. In any case, it's a matter of setting the grid's CurrentRowIndex to be the index of the row you want to highlight. This isn't a great solution, but it should solve your immediate need. -- Ken

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 2
'The DataGrid has a protected GridVScrolled member that can be used to scroll the grid. To use it, you can derive from DataGrid and add a ScrollToRow method.

Public Sub ScrollToRow(ByVal row As Integer)

If Not Me.DataSource Is Nothing Then
Me.GridVScrolled(Me, New ScrollEventArgs(ScrollEventType.LargeIncrement, row))
End If

End Sub 'ScrollToRow

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 3
Very cool. Didn't notice that GridVScrolled method until later, after this thread was posted. I've used it a few times since then. Good catch!
codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 4
If you want to scroll to a row that is not visible (say, you want to show row 100 ) you can set the DataGrid::CurrentCell to new DataGridCell(100, 0)
codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...