I am calling scrollintoviewAsync method of gridview and it is moving scroll to correct row position by changing vertical scroll bar position.
It also changes horizontal scroll position.I want to maintain horizontal scroll position.how i can keep horizontal scroll bar position
Please suggest.
Thanks,
Rajesh
6 Answers, 1 is accepted
Hello Rajesh,
You can try to restore the horizontal offset once the vertical scrolling is complete.
double lastHorizontalOffset = 0.0; private void Button1_Click(object sender, RoutedEventArgs e) { var scrollViewer = this.playersGrid.ChildrenOfType<GridViewScrollViewer>().FirstOrDefault(); this.lastHorizontalOffset = scrollViewer.HorizontalOffset; this.playersGrid.ScrollIntoViewAsync(this.playersGrid.Items[5], new Action<FrameworkElement>(OnScrolled)); } private void OnScrolled(FrameworkElement obj) { var scrollViewer = this.playersGrid.ChildrenOfType<GridViewScrollViewer>().FirstOrDefault(); scrollViewer.ScrollToHorizontalOffset(this.lastHorizontalOffset); } All the best,
Milan
the Telerik team
I am already using similar kind of code.
double offset= scrollViewer.HorizontalOffset;
this.radcontrol.ScrollIntoViewAsync(this.radcontrol.Items[recordIndex],
new Action<FrameworkElement>((f) =>
{
scrollViewer.ScrollToHorizontalOffset( offset);
}
problem with this is that i can see that horizontal scroll viewer is coming to start position and then again it is restoring its previous position.I don't want to move horizontal scroll bar to start position and then move that to original position.I want to keep same horizontal scroll position throughout the cycle.
Thanks,
Rajesh
Hi Rajesh,
Unfortunately, there is not way to restrict the movement of the horizontal bar when using ScrollIntoView. You could also try this custom implementation of SrollIntoView. The custom approach has it limitations as well = for example, it will not work correctly if rows have different size. In addition to that it will not work when the grid is grouped.
Regards,
Milan
the Telerik team
Thanks,
Rajesh
I forgot to paste the code snippet. Excuse me for that.
private void ScrollIntoViewCustom(object item) { var itemIndex = this.playersGrid.Items.IndexOf(item); var scrollViewer = this.playersGrid.ChildrenOfType<GridViewScrollViewer>().FirstOrDefault(); var firstRow = scrollViewer.ChildrenOfType<GridViewRow>().Where(r => !(r is GridViewNewRow)).FirstOrDefault(); var newItemOffset = itemIndex * firstRow.RenderSize.Height; scrollViewer.ScrollToVerticalOffset(newItemOffset); }Milan
the Telerik team
In my case i have few row details item open.So i think it will not work.Let me know if you have other thought on this,