This is a migrated thread and some comments may be shown as answers.

ScrollToSelectedItem

3 Answers 148 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Bruce
Top achievements
Rank 1
Bruce asked on 06 Feb 2018, 05:54 PM

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);
            }
        }
    }

3 Answers, 1 is accepted

Sort by
0
Accepted
Stefan Nenchev
Telerik team
answered on 07 Feb 2018, 09:41 AM
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
0
Bruce
Top achievements
Rank 1
answered on 07 Feb 2018, 11:40 AM
Fantastic.  I'll wait for the release.
0
Bruce
Top achievements
Rank 1
answered on 16 Mar 2018, 02:11 PM
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.
Tags
ListView
Asked by
Bruce
Top achievements
Rank 1
Answers by
Stefan Nenchev
Telerik team
Bruce
Top achievements
Rank 1
Share this question
or