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
1105
ScrollCellIntoView to center screen
posted

Hi. my application let a user click somewhere and my xamDataGrid should change the selected row/active row accordingly.

I'm using ScrollCellIntoView to make the row visible to the user and it works.

however, this row appear sometimes in the top section and sometimes in the bottom section. I assume that it is related to how it is implemented, something like moving one row up or down until getting to that row.

This is unexpected behavior for my user, I would like to find a way to make it appear in the middle, can you suggest a way?

The code I'm using today is:

grid.SelectionSettings.SelectedRows.Clear();
grid.SelectionSettings.SelectedRows.Add(LogViewer.grid.Rows[rowIndex]);
grid.ScrollCellIntoView(LogViewer.grid.Rows[rowIndex].Cells[0]);

I have also tried to 'trick' the funtion by calling ScrollCellIntoView to 10 lines before, than 10 lines after and than the actual line, 
thinking this will cause it to appear in the middle, but it didn't do anything.

please help...
thanks.
Parents
  • 34810
    Offline posted

    Hello eligazit,

    I would recommend continuing with the "trick" that you are trying at the moment, where you are essentially telling the grid to scroll a cell into view that is 10 lines before or after the actual line that you wish to scroll, but I would recommend checking the count of the collection returned by the XamDataGrid.GetRecordsInView method first. This will allow you to perform a better calculation on where exactly to scroll into view. You may also want to consider using the BringRecordIntoView method as this is more on a "row" scope, but the ScrollCellIntoView method should work, too.

    It is also worth noting that this functionality is currently expected behavior of the grid. When you scroll a cell or record into view that is currently out of view, the grid will determine whether or not the cell or record is above or below the currently shown records. If it is above it (scroll up), the record you are scrolling will appear at the top of the grid, and if below (scroll down), it will show at the bottom. If the cell or record is already in view, these scroll methods will not do anything.

    By using the GetRecordsInView method of the XamDataGrid, you can find the records in view, find the index of those records relative to the one you wish to be scrolled to the middle, and bring an appropriate index into view in order to scroll your record or cell into the "middle" of the grid. I have attached a sample project to demonstrate the above.

    I hope this helps you. Please let me know if you have any other questions or concerns on this matter.

    Sincerely,
    Andrew
    Associate Developer

    XDGScrollIntoViewDemo.zip
Reply Children