In my C# winforms app, I have a datagrid. When the datagrid reloads, I want to set the scrollbar back to where the user had it set. How can I do this?
EDIT: I’m using the old winforms DataGrid control, not the newer DataGridView
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You don’t actually interact directly with the scrollbar, rather you set the
FirstDisplayedScrollingRowIndex. So before it reloads, capture that index, once it’s reloaded, reset it to that index.EDIT: Good point in the comment. If you’re using a
DataGridViewthen this will work. If you’re using the oldDataGridthen the easiest way to do that is to inherit from it. See here: LinkageThe DataGrid has a protected GridVScrolled method that can be used to scroll the grid to a specific row. To use it, derive a new grid from the DataGrid and add a ScrollToRow method.
C# code