private int GetInsertCollectionIndex(TreeListViewItem item)
        {
            int index = -1;

            ReadWriteLock.AcquireReaderLock(-1);
            if (!this.Contains(item))
            {
                switch (SortOrder)
                {
                // No sortorder -> at the end of the collection
                case System.Windows.Forms.SortOrder.None:
                    index = this.Count;
                    break;

                default:
                    for (int i = 0; i < this.Count; i++)
                    {
                        // Change the index for the compare if the order is descending
                        int indexcompare = i;
                        //                SortOrder == System.Windows.Forms.SortOrder.Ascending ?
                        //              i : this.Count - (1 + i);
                        int comp = Comparer.Compare(item, this[indexcompare]);
                        if (comp <= 0)
                        {
                            index = indexcompare;
                            break;
                        }
                    }
                    index = index == -1 ? this.Count : index;
                    break;
                }
            }
            ReadWriteLock.ReleaseReaderLock();
            return(index);
        }
        private int GetInsertTreeListViewIndex(TreeListViewItem item)
        {
            if (TreeListView == null)
            {
                return(-1);
            }
            ReadWriteLock.AcquireReaderLock(-1);
            int collectionindex = GetInsertCollectionIndex(item);

            if (Owner != null)
            {
                int a = 0;
                a++;
            }
            int index = -1;

            // First level item (no parent)
            if (Owner != null && collectionindex != -1)
            {
                if (collectionindex == 0)
                {
                    index = 0;
                }
                else
                {
                    index =
                        this[collectionindex - 1].LastChildIndexInListView + 1;
                }
            }
            else if (Parent != null && collectionindex != -1)
            {
                if (!Parent.Visible || !Parent.IsExpanded)
                {
                    index = -1;
                }
                else
                {
                    if (collectionindex == 0)
                    {
                        index = Parent.Index + 1;
                    }
                    else
                    {
                        index =
                            Parent.Items[collectionindex - 1].LastChildIndexInListView + 1;
                    }
                }
            }
            ReadWriteLock.ReleaseReaderLock();
            return(index);
        }
        /// <summary>
        /// Returns true if this collection contains an item
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public bool Contains(TreeListViewItem item)
        {
            bool res = false;

            ReadWriteLock.AcquireReaderLock(-1);
            foreach (TreeListViewItem elt in this)
            {
                if (item == elt)
                {
                    res = true;
                    break;
                }
            }
            ReadWriteLock.ReleaseReaderLock();
            return(res);
        }