예제 #1
0
        private void RemoveItem(object item)
        {
            TreeListView.Node node;
            if (!m_dictNodes.TryGetValue(item, out node))
            {
                return;
            }

            m_dictNodes.Remove(item);

            // Need to recursively remove all child nodes from the dictionary
            if (node.HasChildren)
            {
                foreach (TreeListView.Node child in GatherNodes(node.Nodes))
                {
                    if (m_dictNodes.ContainsKey(child.Tag))
                    {
                        m_dictNodes.Remove(child.Tag);
                    }
                }
            }

            TreeListView.NodeCollection collection =
                node.Parent != null
                    ? node.Parent.Nodes
                    : m_treeListView.Nodes;

            if (collection.IsReadOnly)
            {
                return;
            }

            collection.Remove(node);
        }
예제 #2
0
        private void AddItem(object item, object parent)
        {
            if (m_dictNodes.ContainsKey(item))
            {
                return;
            }

            TreeListView.Node nodeParent = null;
            if (parent != null)
            {
                m_dictNodes.TryGetValue(parent, out nodeParent);
            }

            TreeListView.Node node =
                CreateNodeForObject(
                    item,
                    m_itemView,
                    m_treeListView.ImageList,
                    m_treeListView.StateImageList,
                    m_dictNodes);

            bool expand = nodeParent != null && m_ExpandWhenNewChildAdded;

            m_dictNodes.Add(item, node);

            // Recursively add any children
            AddChildrenToItemRecursively(
                item,
                node,
                m_view,
                m_itemView,
                m_treeListView.ImageList,
                m_treeListView.StateImageList,
                m_dictNodes);

            TreeListView.NodeCollection collection =
                nodeParent == null
                    ? m_treeListView.Nodes
                    : nodeParent.Nodes;

            // Make sure collection can support having children
            if (collection.IsReadOnly && (collection.Owner != null))
            {
                collection.Owner.IsLeaf = false;
            }

            if (collection.IsReadOnly)
            {
                return;
            }

            // Add to tree
            collection.Add(node);

            if (expand)
            {
                nodeParent.Expanded = true;
            }
        }