Ejemplo n.º 1
0
        private void btnAddChild_Click(object sender, EventArgs e)
        {
            var existingNodes = GetAllNodesFor(tvGroups.SelectedNode);
            var childNodes    = tvGroups.Nodes.Cast <TreeNode>().Where(n => !existingNodes.Contains(n.Name)).ToList();

            if (childNodes.Count == 0)
            {
                MessageBox.Show(@"All possible child nodes have been added", @"No more nodes", MessageBoxButtons.OK);
                return;
            }

            using (var child = new GroupPickerDialog(childNodes)) {
                child.ShowDialog();
                if (child.DialogResult != DialogResult.OK)
                {
                    return;
                }
                SetContextDirty();
                var items         = child.SelectedItems;
                var excludedItems = (from item in items
                                     let node = tvGroups.Nodes.Find(item, false)[0]
                                                let excluded = GetAllNodesFor(node)
                                                               from exclude in excluded
                                                               where item != exclude && items.Contains(exclude)
                                                               select exclude).ToList();
                var rootNode = tvGroups.Nodes.Find(tvGroups.SelectedNode.Name, false)[0];
                foreach (var node in from item in items where !excludedItems.Contains(item) select tvGroups.Nodes.Find(item, false)[0])
                {
                    rootNode.Nodes.Insert(rootNode.GetNodeCount(false), (TreeNode)node.Clone());
                }
            }
            UpdateStats();
            tvGroups.Invalidate();
        }
Ejemplo n.º 2
0
        private void btnAddChild_Click(object sender, EventArgs e)
        {
            var existingNodes = GetAllNodesFor(tvGroups.SelectedNode);
            var childNodes = tvGroups.Nodes.Cast<TreeNode>().Where(n => !existingNodes.Contains(n.Name)).ToList();

            if (childNodes.Count == 0) {
                MessageBox.Show(@"All possible child nodes have been added", @"No more nodes", MessageBoxButtons.OK);
                return;
            }

            using (var child = new GroupPickerDialog(childNodes)) {
                child.ShowDialog();
                if (child.DialogResult != DialogResult.OK) {
                    return;
                }
                SetContextDirty();
                var items = child.SelectedItems;
                var excludedItems = (from item in items
                    let node = tvGroups.Nodes.Find(item, false)[0]
                    let excluded = GetAllNodesFor(node)
                    from exclude in excluded
                    where item != exclude && items.Contains(exclude)
                    select exclude).ToList();
                var rootNode = tvGroups.Nodes.Find(tvGroups.SelectedNode.Name, false)[0];
                foreach (var node in from item in items where !excludedItems.Contains(item) select tvGroups.Nodes.Find(item, false)[0]) {
                    rootNode.Nodes.Insert(rootNode.GetNodeCount(false), (TreeNode) node.Clone());
                }
            }
            UpdateStats();
            tvGroups.Invalidate();
        }