示例#1
0
        // Find 'DataRowView' in _TreeNode collection
        private _TreeNode FindParent(List <_TreeNode> nodes, _TreeNode node)
        {
            foreach (_TreeNode tn in nodes)
            {
                if (tn.Id.Equals(node.IdParent))
                {
                    return(tn);
                }

                // Find in child nodes
                _TreeNode fc = FindParent(tn.Child, node);
                if (fc != null)
                {
                    return(fc);
                }
            }

            return(null);
        }
示例#2
0
        private void SetupRows()
        {
            CancelEventArgs cea = new CancelEventArgs();

            if (SetupingRows != null)
            {
                SetupingRows(this, cea);
                if (cea.Cancel)
                {
                    return;
                }
            }

            this.Rows.Clear();
            _nodes.Clear();
            _topNodes.Clear();

            foreach (DataRowView drv in _bs.List)
            {
                object id       = drv.Row[_key];
                object idParent = drv.Row[_parentKey];

                _TreeNode tn = new _TreeNode(drv, id, idParent);
                _nodes.Add(tn);
            }

            foreach (_TreeNode tn in _nodes)
            {
                _TreeNode parentTn = FindParent(_nodes, tn);
                if (parentTn == null)
                {
                    _topNodes.Add(tn);
                }
            }

            foreach (_TreeNode tn in _topNodes)
            {
                _nodes.Remove(tn);
            }



            bool cont = true;

            while (cont)
            {
                cont = false;

                foreach (_TreeNode tn in _nodes)
                {
                    if (tn.Parent == null)
                    {
                        _TreeNode parentTn = FindParent(_topNodes, tn);
                        if (parentTn == null)
                        {
                            cont = true;
                        }
                        else
                        {
                            parentTn.Child.Add(tn);
                            tn.Parent = parentTn;
                        }
                    }
                }
            }

            InsertDataGridRows(_topNodes, null);

            if (SetupedRows != null)
            {
                SetupedRows(this, new EventArgs());
            }
        }