コード例 #1
0
        private void EditItem(RichTreeViewItem node, int index, Rectangle bounds)
        {
            var item = node.Values[index];

            if (item is string)
            {
                var editor = new RichTreeViewTextEditor(node, index);
                editor.ValueUpdated += EditorValueUpdated;
                editor.SetBounds(bounds.X, bounds.Y, bounds.Width, bounds.Height);
                this.Controls.Add(editor);
            }
            if (item is bool)
            {
                var editor = new RichTreeViewBoolEditor(node, index);
                editor.ValueUpdated += EditorValueUpdated;
                editor.SetBounds(bounds.X, bounds.Y, bounds.Width, bounds.Height);
                this.Controls.Add(editor);
            }
            if (item is IList)
            {
                if (((IList)item).Count > 0)
                {
                    var editor = new RichTreeViewListEditor(node, index);
                    editor.ValueUpdated += EditorValueUpdated;
                    editor.SetBounds(bounds.X, bounds.Y, bounds.Width, bounds.Height);
                    this.Controls.Add(editor);
                }
            }
        }
コード例 #2
0
        private void IsNodeContains(RichTreeViewItem node, Point mouseLocation,
                                    RichTreeViewColumn.CreateEditControl editorControlDel)
        {
            if (node.Values != null)
            {
                for (int i = 0; i < _columns.Count; i++)
                {
                    if (node.Values.Length > i)
                    {
                        if (node.Values[i] != null)
                        {
                            var size = TextRenderer.MeasureText(node.Values[i].ToString(), this.Font);
                            size.Width = _columns[i].Width - 1;

                            var rect = new Rectangle(new Point(_columns[i].OffsetX, node.Location.Y), size);
                            if (rect.Contains(mouseLocation))
                            {
                                if (rect.Width > _columns[i].Width)
                                {
                                    rect.Width = _columns[i].Width;
                                }
                                _columns[i].CreateColumnEditor = editorControlDel;
                                _columns[i]?.CreateColumnEditor.Invoke(node, i, rect);
                            }
                        }
                    }
                }
            }

            foreach (RichTreeViewItem subnode in node.Children)
            {
                IsNodeContains(subnode, mouseLocation, editorControlDel);
            }
        }
コード例 #3
0
 public RichTreeViewBoolEditor(RichTreeViewItem node, int index)
 {
     _node  = node;
     _index = index;
 }
コード例 #4
0
 public RichTreeViewTextEditor(RichTreeViewItem node, int valueIndex)
 {
     _node  = node;
     _index = valueIndex;
 }
コード例 #5
0
 public RichTreeViewListEditor(RichTreeViewItem node, int index)
 {
     _node           = node;
     _index          = index;
     this.DataSource = _node.Values[_index];
 }
コード例 #6
0
        private void DisplayRichTreeView(RichTreeViewItem node, PaintEventArgs e)
        {
            if (node.Icon != null)
            {
                e.Graphics.DrawImage(node.Icon, new Rectangle(_richTreeViewLocation, new Size(14, 14)));
                _richTreeViewLocation.X += 20;
            }

            node.ItemsChanged      += (sender, eventArgs) => { this.Invalidate(); };
            node.VisibilityChanged += (sender, eventArgs) => { this.Invalidate(); };

            Size stringSize = TextRenderer.MeasureText(node.Text, this.Font);

            DrawString(node.Text, e, new Rectangle(_richTreeViewLocation, stringSize));

            int offset = _richTreeViewLocation.X + stringSize.Width;

            if (offset > _treeNodeMaxOffsetX)
            {
                _treeNodeMaxOffsetX = offset;
                this.Invalidate();
            }

            node.Location = _richTreeViewLocation;

            if (node.Values != null)
            {
                int valueOffset = _treeNodeMaxOffsetX;

                for (int i = 0; i < node.Values.Length; i++)
                {
                    string item = "";
                    if (node.Values[i] != null)
                    {
                        if (node.Values[i] is IList)
                        {
                            var currItem = ((IList)node.Values[i]);

                            if (currItem.Count > 0)
                            {
                                if (node.SelectedItems != null)
                                {
                                    foreach (var selectedItem in node.SelectedItems)
                                    {
                                        if (selectedItem.Key == i)
                                        {
                                            item = currItem[selectedItem.Value].ToString();
                                        }
                                    }
                                }
                                else
                                {
                                    item = currItem[0].ToString();
                                    node.SelectedItems = new System.Collections.Generic.Dictionary <int, int>();
                                    node.SelectedItems.Add(i, 0);
                                }
                            }
                            else
                            {
                                item = "Empty list";
                            }
                        }
                        else
                        {
                            item = node.Values[i].ToString();
                        }
                    }

                    SizeF size = e.Graphics.MeasureString(item, this.Font);
                    if (_columns.Count > i)
                    {
                        size.Width = _columns[i].Width <= 0 ? 1 : _columns[i].Width;
                        _columns[i].DrawColumnItem?.Invoke(item, e, new RectangleF(valueOffset, _richTreeViewLocation.Y, size.Width, size.Height));
                        valueOffset += _columns[i].Width;
                    }
                }
            }

            int nodesOffsetY = TextRenderer.MeasureText(node.Text, this.Font).Height + 5;

            _richTreeViewLocation.Y += nodesOffsetY;

            _richTreeViewLocation.X += _treeNodesOffsetX;

            if (!node.IsHidden)
            {
                foreach (var subnode in node.Children)
                {
                    DisplayRichTreeView(subnode, e);
                }
            }

            _richTreeViewLocation.X -= _treeNodesOffsetX;
        }