Posted 11 September 2018, 8:41 pm EST
- Updated 4 October 2022, 12:14 am EST
Hello Eric,
ScrollToVerticalOffset method is used to scroll the grid contents to a specified position, which is calculated by the number of rows currently visible in grid. Therefore, C1DataGrid’s ScrollToVerticalOffset considers the number of visible rows.
If the child rows of nodes(master rows) above ‘Our Row’ are visible, then the vertical position of ‘Our Row’ in grid would change (increase)(since the visible rows changed). So, the behavior you are observing is by-design.
Now, if you want that the grid should always scroll to ‘Our Row’ irrespective of whether the child rows above are expanded/collapsed, this needs custom implementation. For this, I devised the following approach:
int ourRow = 15;
private void Button_Click(object sender, RoutedEventArgs e)
{
int visRowCount = 0;
foreach (C1.WPF.DataGrid.DataGridRow rw in gridCategories.Rows)
{
if( rw.DetailsPresenter !=null && rw.DetailsVisibility == Visibility.Visible && rw.VerticalOffset< (ourRow + visRowCount) * gridCategories.RowHeight.Value)
{
visRowCount += ((rw.DetailsPresenter as DataGridDetailsPresenter).Content as C1DataGrid).Rows.Count;
}
}
gridCategories.Viewport.ScrollToVerticalOffset((ourRow + visRowCount) * gridCategories.RowHeight.Value);
}
Conceptually, above I am trying to see which rows are master rows and whose children are visible and keeping track of their children. Also, I am checking whether the row is above ‘Our Row’/not. If is not above, then we need not consider it since, it would not affect the vertical position of ‘Our Row’. Could you please check whether the same works at your end.
Note: ‘Our Row’ is the row we want to show at top.
Regards,
Ruchir
ScrollToVerticalOffset.zip