Exemplo n.º 1
0
        private int Reposition(int index)
        {
            if (filtered)
            {
                if (!MatchesFilter(publist[index]))
                {
                    publist.RemoveAt(index);
                    DoListChanged(new ListChangedEventArgs(ListChangedType.ItemDeleted, index));
                    return(-1);
                }
            }
            if (sorted)
            {
                PropertyComparer <T> pc = new PropertyComparer <T>(property, direction);
                T v = publist[index];
                publist.RemoveAt(index);

                int next = 1, offset = 0;
                do
                {
                    next    = pc.Compare(v, publist[offset]);
                    offset += next;
                    if (offset >= publist.Count || offset < 0)
                    {
                        break;
                    }
                } while (next != 0);

                if (offset < 0)
                {
                    publist.Insert(0, v);
                    DoListChanged(new ListChangedEventArgs(ListChangedType.ItemMoved, 0, index));
                    return(0);
                }
                else if (offset >= publist.Count)
                {
                    publist.Add(v);
                    DoListChanged(new ListChangedEventArgs(ListChangedType.ItemMoved, publist.Count - 1, index));
                    return(publist.Count - 1);
                }
                else
                {
                    publist.Insert(offset, v);
                    DoListChanged(new ListChangedEventArgs(ListChangedType.ItemMoved, offset, index));
                    return(offset);
                }
            }
            return(index);
        }
Exemplo n.º 2
0
        protected override void ApplySortCore(PropertyDescriptor property, ListSortDirection direction)
        {
            // Get list to sort
            List <T> items = this.Items as List <T>;

            // Apply and set the sort, if items to sort
            if (items != null)
            {
                PropertyComparer <T> pc = new PropertyComparer <T>(property, direction);
                items.Sort(pc);
                isSorted = true;
            }
            else
            {
                isSorted = false;
            }

            // Let bound controls know they should refresh their views
            this.OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
        }