Results 1 to 12 of 12

Thread: [RESOLVED] programatically scroll datagridview to last row.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Resolved [RESOLVED] programatically scroll datagridview to last row.

    How can i scroll my datagridview to its last row in the underlying dataset.
    I am doing this because i want to see the value inserted in.
    NOTE:I am not using bindingsource to fill my datagridview.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: programatically scroll datagridview to last row.

    Do you mean show the last row without selecting it or actually selecting the last row?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: programatically scroll datagridview to last row.

    showing the last row, but showing and selecting it too will be more flavor.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: programatically scroll datagridview to last row.

    Still looking forward to resolving this.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: programatically scroll datagridview to last row.

    VB Code:
    1. 'Scroll to the last row.
    2. Me.DataGridView1.FirstDisplayedScrollingRowIndex = Me.DataGridView1.RowCount - 1
    3.  
    4. 'Select the last row.
    5. Me.DataGridView1.Rows(Me.DataGridView1.RowCount - 1).Selected = True
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: programatically scroll datagridview to last row.

    Thanks.

  7. #7
    Lively Member
    Join Date
    Mar 2007
    Posts
    78

    Re: [RESOLVED] programatically scroll datagridview to last row.

    this thread just helped me out.
    Thanks jmcilhinney.

    In my case, a grid is always open, fetching records from a text file, which is being populated continously. The last row gets selected but when new rows are added, multiple rows are selected.
    I can traverse all the rows and unselect them before selecting the last row. but i am talking about 50000 rows here.

    Any advice.
    Regards.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [RESOLVED] programatically scroll datagridview to last row.

    Quote Originally Posted by cyberpd View Post
    this thread just helped me out.
    Thanks jmcilhinney.

    In my case, a grid is always open, fetching records from a text file, which is being populated continously. The last row gets selected but when new rows are added, multiple rows are selected.
    I can traverse all the rows and unselect them before selecting the last row. but i am talking about 50000 rows here.

    Any advice.
    Regards.
    Code:
    For Each row As DataGridViewRow In Me.DataGridView1.SelectedRows
        row.Selected = False
    Next
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9
    Lively Member
    Join Date
    Mar 2007
    Posts
    78

    Re: [RESOLVED] programatically scroll datagridview to last row.

    Fantastic.
    You made my day.

    Thanks and Regards

  10. #10
    New Member
    Join Date
    Sep 2010
    Posts
    1

    Re: [RESOLVED] programatically scroll datagridview to last row.

    You can use too : Me.DataGridView1.ClearSelection()



    'Scroll to the last row.
    Me.DataGridView1.FirstDisplayedScrollingRowIndex = Me.DataGridView1.RowCount - 1

    'Clear the last selection
    'Me.DataGridView1.ClearSelection()

    'Select the last row.
    Me.DataGridView1.Rows(Me.DataGridView1.RowCount - 1).Selected = True

  11. #11
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: [RESOLVED] programatically scroll datagridview to last row.

    Why are you replying to a post that is almost a year old and resolved?


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  12. #12
    Lively Member
    Join Date
    Feb 2015
    Posts
    102

    Re: programatically scroll datagridview to last row.

    Quote Originally Posted by jmcilhinney View Post
    VB Code:
    1. 'Scroll to the last row.
    2. Me.DataGridView1.FirstDisplayedScrollingRowIndex = Me.DataGridView1.RowCount - 1
    3.  
    4. 'Select the last row.
    5. Me.DataGridView1.Rows(Me.DataGridView1.RowCount - 1).Selected = True
    thank you very much i was search for select last rows add with auto timer refresh
    change code a bit with timer
    Code:
    Private Sub Timer5_Tick(sender As Object, e As EventArgs) Handles Timer5.Tick
            UpdateDGV2()
    
    
        End Sub
        Private Sub UpdateDGV2()
            'Scroll to the last row.
            Me.Table_reportDataGridView.FirstDisplayedScrollingRowIndex = Me.Table_reportDataGridView.RowCount - 1
    
            'Select the last row.
            Me.Table_reportDataGridView.Rows(Me.Table_reportDataGridView.RowCount - 1).Selected = True
        End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width