public override void OnDrop(IListDragAndDropArgs args) { var insertAtId = m_TreeView.GetIdForIndex(args.insertAtIndex); var insertAtParentId = m_TreeView.GetParentIdForIndex(args.insertAtIndex); var insertAtChildIndex = m_TreeView.viewController.GetChildIndexForId(insertAtId); if (args.dragAndDropPosition == DragAndDropPosition.OverItem || (insertAtId == -1 && insertAtParentId == -1 && insertAtChildIndex == -1)) { for (var i = 0; i < m_SelectedIndices.Count; i++) { var index = m_SelectedIndices[i]; var id = m_TreeView.GetIdForIndex(index); var parentId = insertAtId; var childIndex = -1; m_TreeView.viewController.Move(id, parentId, childIndex, false); } } else { for (var i = m_SelectedIndices.Count - 1; i >= 0; --i) { var index = m_SelectedIndices[i]; var id = m_TreeView.GetIdForIndex(index); var parentId = insertAtParentId; var childIndex = insertAtChildIndex; m_TreeView.viewController.Move(id, parentId, childIndex, false); } } m_TreeView.viewController.RebuildTree(); m_TreeView.RefreshItems(); }
internal static void AddItem(BaseTreeView treeView, TreeViewItemData <T> item, int parentId = -1, int childIndex = -1, bool rebuildTree = true) { if (treeView.viewController is TDefaultController defaultController) { defaultController.AddItem(item, parentId, childIndex, rebuildTree); if (rebuildTree) { treeView.RefreshItems(); } return; } Type dataSourceType = null; if (treeView.viewController?.GetType().GetGenericTypeDefinition() == typeof(TDefaultController).GetGenericTypeDefinition()) { dataSourceType = treeView.viewController?.GetType().GetGenericArguments()[0]; } throw new ArgumentException($"Type parameter ({typeof(T)}) differs from data source ({dataSourceType})and is not recognized by the controller."); }