TreeNode CreateNode(TreeNodeData d, bool isTopLevel = true)
        {
            TreeNode n = d.Checkable ? new TreeNode() : new HiddenCheckBoxTreeNode();

            n.Text = d.Caption;
            n.Tag  = d;
            if (d.Checkable)
            {
                n.Checked = evts.IsNodeChecked(d);
            }
            foreach (var c in d.Children)
            {
                n.Nodes.Add(CreateNode(c, false));
            }
            if (isTopLevel)
            {
                n.Expand();
            }
            return(n);
        }
Exemplo n.º 2
0
        public override void AwakeFromNib()
        {
            base.AwakeFromNib();

            Window.owner = this;

            collapseAllLinkLabel.StringValue = "collapse all";
            collapseAllLinkLabel.LinkClicked = (s, e) =>
            {
                foreach (var item in dataSource.Items)
                {
                    treeView.CollapseItem(item, collapseChildren: true);
                }
            };

            uncheckAllLinkLabel.StringValue = "uncheck all";
            uncheckAllLinkLabel.LinkClicked = (s, e) =>
            {
                var checkedNodes = dataSource.Items
                                   .SelectMany(i => i.Traverse())
                                   .Where(n => n.Data.Checkable)
                                   .Where(n => evts.IsNodeChecked(n.Data))
                                   .ToArray();
                evts.OnNodesChecked(checkedNodes.Select(n => n.Data).ToArray(), false);
                foreach (var item in checkedNodes)
                {
                    treeView.ReloadItem(item, reloadChildren: false);
                }
            };


            treeView.Delegate = new TreeDelegate()
            {
                owner = this
            };
            treeView.DataSource = dataSource;
        }