New
Last Updated: 07 Dec 2018 12:21 by ADMIN
ADMIN
Hristo
Created on: 07 Dec 2018 12:20
Category: DropDownList/ListControl
Type: Bug Report
0
FIX. RadListControl - exception while performing drag-and-drop with multiple items
How to reproduce: check the attached file

Workaround: create a custom drag-drop service 
public class CustomListControlDragDropService : ListControlDragDropService
{
    private RadListDataItem draggedItem;

    public CustomListControlDragDropService(RadListElement owner) 
        : base(owner)
    {
    }

    protected override void PerformStart()
    {
        base.PerformStart();

        RadListVisualItem draggedVisualItem = this.Context as RadListVisualItem;
        if (draggedVisualItem != null)
        {
            this.draggedItem = draggedVisualItem.Data;
        }
    }

    protected override void PerformStop()
    {
        base.PerformStop();

        this.DisposeHint();
        this.draggedItem = null;
    }

    protected override void OnPreviewDragDropCore(RadListElement targetList, RadListVisualItem targetElement)
    {
        int index = targetList.Items.Count - 1;
        if (targetElement != null)
        {
            index = targetList.Items.IndexOf(targetElement.Data);
        }
        
        if (this.draggedItem.Owner != targetList)
        {
            index++;
        }
        RadListElement dragedListView = this.draggedItem.Owner;

        IList<RadListDataItem> itemsToMove = new List<RadListDataItem>(dragedListView.SelectedItems.Count);

        foreach (RadListDataItem item in dragedListView.SelectedItems)
        {
            itemsToMove.Add(item);
        }

        dragedListView.BeginUpdate();
        foreach (RadListDataItem item in itemsToMove)
        {
            item.Selected =
                item.Active = false;
            dragedListView.Items.Remove(item);
        }

        dragedListView.EndUpdate();
        targetList.BeginUpdate();
        foreach (RadListDataItem item in itemsToMove)
        {
            if (index > targetList.Items.Count)
            {
                targetList.Items.Add(item);
            }
            else
            {
                targetList.Items.Insert(index, item);
            }

            item.Selected = item.Active = true;

            index++;
        }

        targetList.EndUpdate();
    }
}
Attached Files:
(Total attached files size should be smaller than 20mb. Allowed extensions: .zip, .rar, .jpg, .png, .gif)
0 comments