ScrollToSelectedItem

4 posts, 1 answers
  1. Bruce
    Bruce avatar
    34 posts
    Member since:
    Oct 2010

    Posted 06 Feb 2018 Link to this post

    I change a RadListView's SelectedItem programmatically.  When I do, I need RadListView to scroll to the new SelectedItem.  This thread discusses the issue:  https://www.telerik.com/forums/implementing-scroll-to-item

    My Solution has both Android and iOS projects.  I'm starting with iOS by implementing the class shown below.  The code does not crash, but neither does it work.  Any hints or ideas you have would be most welcome.  I also need to get this working on Android.

    Thanks in advance for your help.

    P.S. My initial impression is that this scrolling should be included out-of-the-box.  Please consider this an enhancement request.

    public class RadListViewRenderer : Telerik.XamarinForms.DataControlsRenderer.iOS.ListViewRenderer

        {
            private RadListView listView = null;
            private NSIndexPath indexPath;
            protected override void OnElementChanged(ElementChangedEventArgs<RadListView> e)
            {
                base.OnElementChanged(e);
                listView = e.NewElement;
                if (listView != null)
                {
                    listView.SelectionChanged += selectionChanged;
                }
            }

            private void selectionChanged(object sender, NotifyCollectionChangedEventArgs args)
            {
                if (args.NewItems?.Count > 0 && listView != null)
                {
                    int index = (int)listView.ItemsSource.GetType().GetMethod("IndexOf").Invoke(listView.ItemsSource, new[] {args.NewItems[0]});
                    indexPath = NSIndexPath.FromItemSection(index, 0);
                    Control.ScrollToItem(indexPath, UICollectionViewScrollPosition.Top, false);
                }
            }
        }

  2. Answer
    Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    665 posts

    Posted 07 Feb 2018 Link to this post

    Hello, Bruce,

    Actually, we are currently working on adding such scrolling mechanism in Forms. It will be included in the next service pack release which will be available on the 21st of February. Here is the public item for your reference - ListView: Expose Scrolling API. Would it be convenient for you to wait until the 21st and test the behavior once the functionality is available?

    Have a great rest of the week.

    Regards,
    Stefan Nenchev
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Bruce
    Bruce avatar
    34 posts
    Member since:
    Oct 2010

    Posted 07 Feb 2018 in reply to Stefan Nenchev Link to this post

    Fantastic.  I'll wait for the release.
  4. Bruce
    Bruce avatar
    34 posts
    Member since:
    Oct 2010

    Posted 16 Mar 2018 Link to this post

    Just tried it.  I was under the impression that I had to implement the feature.  Not so.  I simply selected an item at the bottom of my list and the grid scrolled to it.  Very nice; thanks.
Back to Top