Link to home
Start Free TrialLog in
Avatar of billyboy71
billyboy71

asked on

get datagridview to show last record instead of first.

Hi,
I was wondering is it possible to get the DATAGRID VIEW to show the last record instead of the first when it is initially loaded.

I am using VB.net with a Windows Form to display a table from Access 2003.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DataSet2.tblBeverages' table. You can move, or remove it, as needed.
        Me.TblBeveragesTableAdapter.Fill(Me.DataSet2.tblBeverages)

Open in new window

Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Hi billyboy71,

Ho do you define last record ? Do you have any Id, date, etc ?

You can sort the datagridview to do that after you fill it.
Avatar of billyboy71
billyboy71

ASKER

Hi,
Well, the last record in terms of the last row?
I was thinking about using FirstDisplayedScrollingRowIndex , but I can't seem to get it to work.

Peter
ASKER CERTIFIED SOLUTION
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,
Thanks for the reply.  I tried the suggestions above. But I can't seem to get the arrow pointer to go to the particular row when the datagridview is loaded .  Is there some execute command that I need to carry out?

Peter
Hi,

Thanks for your reply.  Now , I can get the arrow pointer to scroll to the button , but only when I put the the command in a particular method such as when I put the command in a button click.

But I want it to got to that row when the form appears.

Peter
Hi,

Is there some kind of method for the Form or Tab, Such as Form.Onfocus or Tab.Onfocus so that it can execute the method of DataGridView.FirstDisplayedScrollingRowIndex  = 3 ?

Otherwise, the form just won't execute it unless I put it in a button on_click method or somethign.

peter
Hi,

This is strange it can't carry out that command on the FORM LOAD event. But I can do it on the Button Click event.

Me.DataGridView2.FirstDisplayedScrollingRowIndex = Me.DataGridView2.RowCount - 1

Peter

Hi Peter,

This selects the record and show the arrow pointer.
Me.DataGridView.Rows(3).Selected = True

Can you show your code that you are trying to use ? If you are using this on form load maybe it's to quick and doesn't see anything. Try to do this way or you can add a timer to delay this action:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Me.TblBeveragesTableAdapter.Fill(Me.DataSet2.tblBeverages)
       Applications.DoEvents()
       Me.DataGridView2.FirstDisplayedScrollingRowIndex = Me.DataGridView2.RowCount - 1
End Sub
Hi Ipaulino,

I found out what my problem was. The first code that you gave works now. The problem was that my Datagridview was inside a Tab Control. So in order to get it to work I had to put the code in the Tab Control event.

Thanks a lot.

Peter



 Private Sub TabControl1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.Click
        Me.DataGridView2.FirstDisplayedScrollingRowIndex = Me.DataGridView2.RowCount - 1
    End Sub

Open in new window

>> The problem was that my Datagridview was inside a Tab Control. So in order to get it to work I had to put the code in the Tab Control event.
It happens allot! :-)

Glad I could help and thank for the grade!