コード例 #1
0
        private void KeepSelection(Action update)
        {
            var selectedNodes = new HashSet <object>(tree.SelectedNodes.Select(node => node.Tag).Where(tag => tag != null));

            tree.SelectedNodes.Clear();
            bool selectionIsDifferent = false;

            update();

            try
            {
                // Update nodes
                _changing = true;

                // Restore selection
                var newSelectedNodes = new List <DarkTreeNode>();
                foreach (DarkTreeNode node in CollectAllNodes(tree.Nodes))
                {
                    if (node.Tag != null)
                    {
                        if (selectedNodes.Contains(node.Tag))
                        {
                            newSelectedNodes.Add(node);
                        }
                    }
                }
                tree.SelectNodes(newSelectedNodes);
                selectionIsDifferent = newSelectedNodes.Count != selectedNodes.Count;
            }
            finally
            {
                _changing = false;
            }

            // See if anything changed in the selection
            if (selectionIsDifferent)
            {
                SelectedWadObjectIdsChanged?.Invoke(this, EventArgs.Empty);
            }

            // Workaround update problems
            Invalidate();
        }
コード例 #2
0
        public WadTreeView()
        {
            InitializeComponent();

            SetStyle(ControlStyles.OptimizedDoubleBuffer |
                     ControlStyles.ResizeRedraw |
                     ControlStyles.UserPaint, true);

            tree.SelectedNodes.CollectionChanged += (s, e) => { if (!_changing)
                                                                {
                                                                    SelectedWadObjectIdsChanged?.Invoke(this, EventArgs.Empty);
                                                                }
            };

            // Populate game version
            foreach (var gameVersion in TRVersion.NativeVersions)
            {
                suggestedGameVersionComboBox.Items.Add(gameVersion);
            }
        }