Пример #1
0
        public void AddItem()
        {
            DataItem parent = (DataItem)TreeView.SelectedItem;

            if (parent == null)
            {
                parent = TreeView.Items.OfType <DataItem>().First();
            }

            for (int i = 0; i < 1; i++)
            {
                DataItem item = new DataItem("New Item " + i);
                item.Parent = parent;
                parent.Children.Add(item);
            }

            VirtualizingItemContainer itemContainer = TreeView.GetItemContainer(parent);

            if (itemContainer != null)
            {
                //Update arrow visiblity
                TreeView.DataBindItem(parent, itemContainer);
                TreeView.Expand(parent);
            }
        }
Пример #2
0
        void IEndDragHandler.OnEndDrag(PointerEventData eventData)
        {
            if (TreeView.DropTarget != null)
            {
                GameObject dropTarget  = (GameObject)TreeView.DropTarget;
                GameObject newDataItem = new GameObject();
                VirtualizingTreeViewItem treeViewItem = (VirtualizingTreeViewItem)TreeView.GetItemContainer(TreeView.DropTarget);

                if (TreeView.DropAction == ItemDropAction.SetLastChild)
                {
                    newDataItem.transform.SetParent(dropTarget.transform);
                    TreeView.AddChild(TreeView.DropTarget, newDataItem);
                    treeViewItem.CanExpand  = true;
                    treeViewItem.IsExpanded = true;
                }
                else if (TreeView.DropAction != ItemDropAction.None)
                {
                    int index;
                    if (TreeView.DropAction == ItemDropAction.SetNextSibling)
                    {
                        index = TreeView.IndexOf(dropTarget) + 1;
                    }
                    else
                    {
                        index = TreeView.IndexOf(dropTarget);
                    }

                    newDataItem.transform.SetParent(dropTarget.transform.parent);
                    newDataItem.transform.SetSiblingIndex(index);

                    TreeViewItemContainerData newTreeViewItemData = (TreeViewItemContainerData)TreeView.Insert(index, newDataItem);
                    VirtualizingTreeViewItem  newTreeViewItem     = (VirtualizingTreeViewItem)TreeView.GetItemContainer(newDataItem);
                    if (newTreeViewItem != null)
                    {
                        newTreeViewItem.Parent = treeViewItem.Parent;
                    }
                    else
                    {
                        newTreeViewItemData.Parent = treeViewItem.Parent;
                    }
                }
            }

            TreeView.ExternalItemDrop();
        }