Exemplo n.º 1
0
        public virtual int Add(TreeNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            int      index;
            TreeView tree_view = null;

            if (owner != null)
            {
                tree_view = owner.TreeView;
            }

            if (tree_view != null && UsingSorting)
            {
                index = AddSorted(node);
            }
            else
            {
                if (count >= nodes.Length)
                {
                    Grow();
                }
                index = count;
                count++;
                nodes[index] = node;
            }

            SetupNode(node);
#if NET_2_0
            // UIA Framework Event: Collection Changed
            if (tree_view != null)
            {
                tree_view.OnUIACollectionChanged(owner, new CollectionChangeEventArgs(CollectionChangeAction.Add, node));
            }
#endif
            return(index);
        }
Exemplo n.º 2
0
 // UIA Framework Event: Collection Changed
 private void OnUIACollectionChanged(CollectionChangeAction action, TreeNode node)
 {
     TreeView?.OnUIACollectionChanged(owner, new CollectionChangeEventArgs(action, node));
 }
Exemplo n.º 3
0
        private void RemoveAt(int index, bool update)
        {
            TreeNode removed         = nodes [index];
            TreeNode prev            = GetPrevNode(removed);
            TreeNode new_selected    = null;
            bool     re_set_selected = false;
            bool     visible         = removed.IsVisible;

            TreeView tree_view = null;

            if (owner != null)
            {
                tree_view = owner.TreeView;
            }

            if (tree_view != null)
            {
                tree_view.RecalculateVisibleOrder(prev);

                if (removed == tree_view.SelectedNode)
                {
                    if (removed.IsExpanded)
                    {
                        removed.Collapse();                             // Fix Xamarin Bugzilla 5010.
                    }
                    re_set_selected = true;
                    OpenTreeNodeEnumerator oe = new OpenTreeNodeEnumerator(removed);
                    if (oe.MoveNext() && oe.MoveNext())
                    {
                        new_selected = oe.CurrentNode;
                    }
                    else
                    {
                        oe = new OpenTreeNodeEnumerator(removed);
                        oe.MovePrevious();
                        new_selected = oe.CurrentNode == removed ? null : oe.CurrentNode;
                    }
                }
            }

            Array.Copy(nodes, index + 1, nodes, index, count - index - 1);
            count--;

            nodes[count] = null;

            if (nodes.Length > OrigSize && nodes.Length > (count * 2))
            {
                Shrink();
            }

            if (tree_view != null && re_set_selected)
            {
                tree_view.SelectedNode = new_selected;
            }

            TreeNode parent = removed.parent;

            removed.parent = null;

            if (update && tree_view != null && visible)
            {
                tree_view.RecalculateVisibleOrder(prev);
                tree_view.UpdateScrollBars(false);
                tree_view.UpdateBelow(parent);
            }

            // UIA Framework Event: Collection Changed
            if (tree_view != null)
            {
                tree_view.OnUIACollectionChanged(owner, new CollectionChangeEventArgs(CollectionChangeAction.Remove, removed));
            }
        }