We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to get the dropped item group in Xamarin.Forms ListView (SfListView)

Platform: Xamarin.Forms |
Control: SfListView |
Published Date: April 22, 2020 |
Last Revised Date: July 22, 2020

You can get the drop item group in Xamarin.Forms SfListView using DisplayItems.

C#

Get the group details after dragging in ItemDragging event when the action is Drop. Get the drop item index using NewIndex from ItemDraggingEventArgs.

namespace ListViewXamarin
{
    public class Behavior : Behavior<ContentPage>
    {
        SfListView ListView;
 
        protected override void OnAttachedTo(ContentPage bindable)
        {
            ListView = bindable.FindByName<SfListView>("listView");
            ListView.ItemDragging += ListView_ItemDragging;
 
            base.OnAttachedTo(bindable);
        }
 
        private void ListView_ItemDragging(object sender, ItemDraggingEventArgs e)
        {
            if (e.Action == DragAction.Drop)
            {
                int dropIndex = e.NewIndex;
                var dropItem = ListView.DataSource.DisplayItems[dropIndex];
                var dropedGroup = GetGroup(dropItem, e);
 
                App.Current.MainPage.DisplayAlert("Dropped group", "" + dropedGroup.Key, "Ok");
            }
        }
 
        public GroupResult GetGroup(object itemData, ItemDraggingEventArgs args)
        {
            GroupResult itemGroup = null;
 
            foreach (var item in this.ListView.DataSource.DisplayItems)
            {
                if(itemData is GroupResult)
                {
                    if (args.OldIndex > args.NewIndex && item == itemData) break;
                    if (item is GroupResult) itemGroup = item as GroupResult;
                    if (args.OldIndex < args.NewIndex && item == itemData) break;
                }
                else
                {
                    if (item == itemData) break;
                    if (item is GroupResult) itemGroup = item as GroupResult;
                }
            }
            return itemGroup;
        }
    }
}

 Output

Demo to get group details of the drop item in Xamarin.Forms SfListView.

View sample in GitHub

2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon