BrightIdeasSoftware.ObjectListView.MoveObjects C# (CSharp) Method

MoveObjects() public method

Move the given collection of objects to the given index.
This operation only makes sense on non-grouped ObjectListViews.
public MoveObjects ( int index, ICollection modelObjects ) : void
index int
modelObjects ICollection
return void
        public virtual void MoveObjects(int index, ICollection modelObjects)
        {
            // We are going to remove all the given objects from our list
            // and then insert them at the given location
            this.TakeOwnershipOfObjects();
            ArrayList ourObjects = ObjectListView.EnumerableToArray(this.Objects, false);

            List<int> indicesToRemove = new List<int>();
            foreach (object modelObject in modelObjects) {
                if (modelObject != null) {
                    int i = this.IndexOf(modelObject);
                    if (i >= 0) {
                        indicesToRemove.Add(i);
                        ourObjects.Remove(modelObject);
                        if (i <= index)
                            index--;
                    }
                }
            }

            // Remove the objects in reverse order so earlier
            // deletes don't change the index of later ones
            indicesToRemove.Sort();
            indicesToRemove.Reverse();
            try {
                this.BeginUpdate();
                foreach (int i in indicesToRemove) {
                    this.Items.RemoveAt(i);
                }
                this.InsertObjects(index, modelObjects);
            } finally {
                this.EndUpdate();
            }
        }
ObjectListView