/*
         * public MSTreeViewItem GetItemFromData(int i)
         * {
         *  return (MSTreeViewItem)(this.ItemContainerGenerator.ContainerFromIndex(i));
         * }
         */

        private MSTreeViewItem HasSidlingItem(MSTreeViewItem item)
        {
            MSTreeViewItem parent = item.GetParentTreeViewItem();

            if (parent == null)
            {
                return(null);
            }

            MSTreeViewItem sidling = null;

            foreach (var obj in parent.Items)
            {
                //object i = GetItemFromData(parent.Items.IndexOf(obj));

                // if (obj == null)
                //     continue;
                MSTreeViewItem i = parent.GetChildItemFromData(obj);
                if (i != item && i.IsSelected)
                {
                    sidling = i;
                    break;
                }
            }
            return(sidling);
        }
        private void SelectBetween(MSTreeViewItem item1, MSTreeViewItem item2)
        {
            //if (item1.Parent != item2.Parent)
            //    return;

            MSTreeViewItem parent  = item1.GetParentTreeViewItem();
            int            index_1 = parent.Items.IndexOf(item1.DataContext);
            int            index_2 = parent.Items.IndexOf(item2.DataContext);

            if (index_1 < index_2)
            {
                for (int i = index_1; i < index_2; i++)
                {
                    MSTreeViewItem item = parent.GetChildItemFromData(parent.Items[i]);
                    if (item == null)
                    {
                        continue;
                    }

                    item.Select();
                }
            }
            if (index_1 > index_2)
            {
                for (int i = index_1; i > index_2; i--)
                {
                    MSTreeViewItem item = parent.GetChildItemFromData(parent.Items[i]);
                    if (item == null)
                    {
                        continue;
                    }

                    item.Select();
                }
            }
            SortSelectedItems(parent.Items);
        }