Exemplo n.º 1
0
        private void value_RowDeleting(object sender, DataRowChangeEventArgs e)
        {
            TreeNodeBound node = (TreeNodeBound)_nodesByValueMember[e.Row[this._valueMember]];

            _nodesByValueMember.Remove(node);
            if (node.TreeView != null)
            {
                node.Remove();
            }
        }
Exemplo n.º 2
0
        private void LoadTree()
        {
            if (this._datasource != null && this._displayMember != null && this._valueMember != null && this._parentMember != null)
            {
                Clear();

                if (this.ComboTreeType != ComboTreeType.None)
                {
                    TreeNodeBound nullnode = new TreeNodeBound(this.TypeText);
                    nullnode.Value       = this.ComboTreeType.ToString();
                    nullnode.Name        = nullnode.Value.ToString();
                    nullnode.ParentValue = this.ComboTreeType.ToString();
                    this.Nodes.Add(nullnode);
                }

                foreach (DataRow dr in this._datasource.Rows)
                {
                    TreeNodeBound node = new TreeNodeBound(dr[this._displayMember].ToString());
                    node.Value       = dr[this._valueMember];
                    node.Name        = node.Value.ToString();
                    node.ParentValue = dr[this._parentMember];

                    _nodesByValueMember.Add(node);
                }

                foreach (TreeNodeBound node in _nodesByValueMember)
                {
                    if ((node.ParentValue == _rootParentValue) || (node.ParentValue.ToString() == node.Value.ToString()))
                    {
                        //the node is a Root, add it to the root collection
                        this.Nodes.Add(node);
                    }
                    else
                    {
                        //look for the parent
                        TreeNodeBound parent = (TreeNodeBound)_nodesByValueMember[node.ParentValue];
                        if (parent != null)
                        {
                            //add it to the nodes collection of the parent node
                            parent.Nodes.Add(node);
                        }
                        else
                        {
                            throw new ArgumentException("Node with Value = " + Convert.ToString(node.ParentValue) + " does not exist. The referencing node has a value = " + Convert.ToString(node.Value) + ". Check your datasource integrity.");
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void value_RowChanged(object sender, DataRowChangeEventArgs e)
        {
            if (e.Action == DataRowAction.Add)
            {
                if (e.Row[this._valueMember] != DBNull.Value)
                {
                    TreeNodeBound node = new TreeNodeBound(e.Row[this.DisplayMember].ToString());
                    node.Value       = e.Row[this._valueMember];
                    node.ParentValue = e.Row[this._parentMember];
                    _nodesByValueMember.Add(node);
                    if (node.ParentValue == _rootParentValue)
                    {
                        //Its a root
                        this.Nodes.Add(node);
                    }
                    else if (_nodesByValueMember[node.ParentValue] != null)
                    {
                        //The parent exist
                        TreeNodeBound parent = (TreeNodeBound)_nodesByValueMember[node.ParentValue];
                        if (parent != null)
                        {
                            parent.Nodes.Add(node);
                        }
                        else
                        {
                            throw new ArgumentException("Node with Value = " + Convert.ToString(node.ParentValue) + " does not exist. The referencing node has a value = " + Convert.ToString(node.Value) + ". Check your datasource integrity.");
                        }

                        if (parent.IsVisible)
                        {
                            parent.Expand();
                        }
                    }
                }
            }
            else if (e.Action == DataRowAction.Change)
            {
                TreeNodeBound node         = (TreeNodeBound)_nodesByValueMember[e.Row[this._valueMember]];
                object        actualParent = e.Row[this._parentMember].ToString();

                //Change parenthood
                if (actualParent.ToString() != node.ParentValue.ToString())
                {
                    if (node.ParentValue != _rootParentValue)
                    {
                        TreeNodeBound oldParent = (TreeNodeBound)_nodesByValueMember[node.ParentValue];
                        if (oldParent != null)
                        {
                            oldParent.Nodes.Remove(node);
                        }
                    }
                    else
                    {
                        //Remove it from the root nodes
                        this.Nodes.Remove(node);
                    }

                    node.ParentValue = e.Row[this._parentMember];

                    if (node.ParentValue != _rootParentValue)
                    {
                        TreeNodeBound newParent = (TreeNodeBound)_nodesByValueMember[node.ParentValue];
                        if (newParent != null) //if exist
                        {
                            newParent.Nodes.Add(node);
                            if (newParent.IsVisible)
                            {
                                newParent.Expand();
                            }
                        }
                    }
                    else
                    {
                        this.Nodes.Add(node);
                    }
                }
                //Change the text
                node.Text = e.Row[this.DisplayMember].ToString();
            }
        }