Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi..
I have a dgv in a form having a number of rows. I have next and previous buttons to move to the respective rows in the dgv. The next and previous are working correctly. The dvg shows 10 rows at a time. When i select the 11th or the upcoming row we can not see that row. So how can i scroll to that row to see it selected?
I think someone can help me.Thanks in advance..
Posted
Updated 21-Aug-21 23:12pm

if i is selected row in dataGridView1 and j is selected column , try :
C#
dataGridView1.FirstDisplayedScrollingRowIndex =i;

C#
dataGridView1.CurrentCell = dataGridView1[j,i];
 
Share this answer
 
v2
Try DataGridView.FirstDisplayedScrollingRowIndex.
 
Share this answer
 
Shift in the column in from left side as requried to show it
public static bool ScrollToColumn(DataGridViewColumn col) {
    if (col.Visible && col.Width > 0) {
        var dgv = col.DataGridView;
        int colRight = 0;
        foreach (DataGridViewColumn _c in dgv.Columns) {
            colRight += _c.Width;
            if (_c == col) break;
        }
        var delta = colRight - dgv.Width;
        if (delta > 0) {
            dgv.HorizontalScrollingOffset = delta;
            return true;
        }
    }
    return false;
}

 
Share this answer
 
Comments
Richard Deeming 23-Aug-21 4:51am    
What precisely does code for scrolling to a COLUMN have to do with an already-solved question about scrolling to a ROW?

If you're going to add a new answer to such an old question, make sure you have read and understood the question first, and that your solution will add something new to the discussion.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900