Articles in this section
Category / Section

How to bring the item into view when adding at runtime in the listview?

1 min read

ListView allows you scroll to the end using the ScrollToRowIndex or ScrollTo method when the items are added into the collection using the DisplayItemCollectionChanged event.

 

If you have header or groupheader, then consider the index and give it to the ScrollToRowIndex method.

C#

listView.DataSource.DisplayItems.CollectionChanged += DisplayItems_CollectionChanged;
 
private async void DisplayItems_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
    if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
    {
        await Task.Delay(100);
        var item = e.NewItems[0];
        var itemIndex = listView.DataSource.DisplayItems.IndexOf(item);
        (listView.LayoutManager as LinearLayout).ScrollToRowIndex(itemIndex, true);
    }
}

 

Sample link: Scroll to the end of the listview when add an item at run time.

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied