Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
445
ScrollRowIntoView Not Working
posted

I am using UltraGrid and needs a way to check if a selected row is still in the view region. The reason is when user double-click a row in the first grid, another grid will show up. So I dynamically shrink the first grid to make room for the second grid, which caused that selected row (if it is in the bottom) to be scrolled outside of the view in the first grid. So after resize, I want to check if that selected row in the first grid is still visible. If not, I want to scroll it into the view. I tried to use ScrollRowIntoView as below and it didn't work. Why??

grid1.ActiveRowScrollRegion.ScrollRowIntoView(grid1.ActiveRow);

I also tried to set the FirstRow in ActiveRowScrollRegion and it worked:

grid1.ActiveRowScrollRegion.FirstRow = grid1.ActiveRow;

But that didn't solve my problem since I don't always want to reposition the active row into the top. Instead, I want to first check if the active row has been scrolled outside of view. If so, make the active row the first row in the view. If not, don't do anything since the row is already visible. Can you please help?

Thanks!

Parents
  • 469350
    Verified Answer
    Offline posted

    Hi,

    My best guess is that this is a timing issue with the event you are using. Which event are you handling that triggers all of this?

    Let's say you are using the grid's DoubleClickRow event. Your code sets the size of the grid and then calls ScrollRowIntoView. But since the code you are running is synchronous, the grid might not have received a paint message, yet, and so the UIElements in the grid are still in the old state and the row is still in view as far as the grid knows, so it does nothing. Then the next time the grid paints, the row ends up out of view.

    If I am right, then all you have to do fix this is to call grid.Update after you change the grid's size/position, but before you call ScrollRowIntoView.

    Another alternative would be to call ScrollRowIntoView asynchronously using a BeginInvoke instead of calling the method directly.

Reply Children
No Data