PKStudio.Tree.InventoryTree.SetModel C# (CSharp) Method

SetModel() public method

public SetModel ( ITreeModel model, bool expandRoot ) : void
model ITreeModel
expandRoot bool
return void
        public void SetModel(ITreeModel model, bool expandRoot)
        {
            if (_treeView.Model == null)
                expandRoot = true;
            string selectedTreePath = null;
            Dictionary<string, bool> collapsing = new Dictionary<string, bool>();

            if (this.SelectedNode != null)
                selectedTreePath = this.SelectedNode.TreePath;

            if (expandRoot == false)
            {
                foreach (TreeNodeAdv node in _treeView.AllNodes)
                {
                    BaseNode tag = node.Tag as BaseNode;
                    if (tag != null)
                    {
                        try
                        {
                            if (node.IsLeaf == false)
                                collapsing.Add(tag.TreePath, node.IsExpanded);
                        }
                        catch
                        {
                        }
                    }
                }
            }

            _treeView.Model = model;

            if (expandRoot)
                ExpandRootNode();
            else
            {
                TreeNodeAdv selectedNode = null;
                _treeView.SuspendLayout();
                foreach (TreeNodeAdv node in _treeView.AllNodes)
                {
                    BaseNode tag = node.Tag as BaseNode;
                    if (tag != null)
                    {
                        if (selectedTreePath != null)
                        {
                            if (selectedTreePath == tag.TreePath)
                            {
                                selectedNode = node;
                            }
                        }
                        bool isExpanded;
                        if (collapsing.TryGetValue(tag.TreePath, out isExpanded))
                            node.IsExpanded = isExpanded;
                    }
                }
                if (selectedNode != null)
                    _treeView.SelectedNode = selectedNode;
                else
                    ExpandRootNode();

                _treeView.ResumeLayout();
            }
        }

Usage Example

Example #1
0
 protected void SetupTree(InventoryTree tree, ITreeModel model, bool expandRoot)
 {
     tree.NodeControls.Clear();
     NodeCheckBox checkBox = tree.AddCheckBoxControl("Checked");
     checkBox.IsVisibleValueNeeded += new EventHandler<NodeControlValueEventArgs>(IsCheckBoxVisible);
     checkBox.IsEditEnabledValueNeeded += new EventHandler<NodeControlValueEventArgs>(IsCheckBoxEnabled);
     checkBox.CheckStateChanged += new EventHandler<TreePathEventArgs>(CheckBoxStateChanged);
     tree.AddIconControl("Icon");
     tree.AddTextBoxControl("Name");
     tree.SetModel(model, expandRoot);
 }