1
Vote

Argument Exception in SectionContainerControl when dragging several items

description

Depending on the way the items are selected, an exception may occur in SectionContainerControl.CreateDragImageWindow when dragging them, because the calculated height is null or negative:
 
int height = sections[sections.Length - 1].Rectangle.Bottom - sections[0].Rectangle.Top;
 
It assumes the sections array is sorted, which is not guaranteed.
 

To solve this issue, transform the RowSection.GetExpandedDragList function from this (sorry for the poor formatting, is there any way to improve that on this site?):

    public override Section[] GetExpandedDragList()
    {
        List<Section> sections = new List<Section>();
        foreach (Section s in ListSection.Children) {
            RowSection rowSection = s as RowSection;
            if (rowSection != null && rowSection.IsSelected) {
                sections.Add(rowSection);
            }
        }
        return sections.ToArray();

}

To this (adding the Sort to ensure the elements are listed top-down):

    public override Section[] GetExpandedDragList()
    {
        List<Section> sections = new List<Section>();
        foreach (Section s in ListSection.Children) {
            RowSection rowSection = s as RowSection;
            if (rowSection != null && rowSection.IsSelected) {
                sections.Add(rowSection);
            }
        }
        sections.Sort((Section x, Section y) => x.Rectangle.Top - y.Rectangle.Top);
        return sections.ToArray();

}

comments