Beispiel #1
0
        protected override void OnMouseDown(DataGridViewCellMouseEventArgs e)
        {
            if (e.Location.X > this.InheritedStyle.Padding.Left)
            {
                base.OnMouseDown(e);
            }
            else
            {
                // Expand the node

                JMTreeGridNode node = this.OwningNode;
                if (node != null)
                {
                    node._grid._inExpandCollapseMouseCapture = true;
                    if (node.IsExpanded)
                    {
                        node.Collapse();
                    }
                    else
                    {
                        node.Expand();
                    }
                }
            }
        }
Beispiel #2
0
        protected override void OnMouseUp(DataGridViewCellMouseEventArgs e)
        {
            base.OnMouseUp(e);

            JMTreeGridNode node = this.OwningNode;

            if (node != null)
            {
                node._grid._inExpandCollapseMouseCapture = false;
            }
        }
Beispiel #3
0
 private void UpdateChildNodes(JMTreeGridNode node)
 {
     if (node.HasChildren)
     {
         foreach (JMTreeGridNode childNode in node.Nodes)
         {
             childNode._grid = node._grid;
             this.UpdateChildNodes(childNode);
         }
     }
 }
Beispiel #4
0
 internal protected virtual bool RemoveChildNode(JMTreeGridNode node)
 {
     if ((this.IsRoot || this._isSited) && this.IsExpanded)
     {
         //We only unsite out child node if we are sited and expanded.
         this._grid.UnSiteNode(node);
     }
     node._grid   = null;
     node._parent = null;
     return(true);
 }
Beispiel #5
0
 internal protected virtual void SiteNode(JMTreeGridNode node, int index)
 {
     if (index < base.Rows.Count)
     {
         base.Rows.Insert(index, node);
     }
     else
     {
         // for the last item.
         base.Rows.Add(node);
     }
 }
Beispiel #6
0
        internal protected virtual bool AddChildNode(JMTreeGridNode node)
        {
            node._parent = this;
            node._grid   = this._grid;

            // ensure that all children of this node has their grid set
            if (this._grid != null)
            {
                UpdateChildNodes(node);
            }

            if ((this._isSited || this.IsRoot) && this.IsExpanded && !node._isSited)
            {
                this._grid.SiteNode(node);
            }

            return(true);
        }
Beispiel #7
0
        //internal VisualStyleRenderer rOpen = new VisualStyleRenderer(VisualStyleElement.TreeView.Glyph.Opened);
        //internal VisualStyleRenderer rClosed = new VisualStyleRenderer(VisualStyleElement.TreeView.Glyph.Closed);

        #region Constructor
        public JMTreeGridView()
        {
            // Control when edit occurs because edit mode shouldn't start when expanding/collapsing
            this.EditMode    = DataGridViewEditMode.EditProgrammatically;
            this.RowTemplate = new JMTreeGridNode() as DataGridViewRow;
            // This sample does not support adding or deleting rows by the user.
            this.AllowUserToAddRows    = false;
            this.AllowUserToDeleteRows = false;
            this._root        = new JMTreeGridNode(this);
            this._root.IsRoot = true;

            // Ensures that all rows are added unshared by listening to the CollectionChanged event.
            base.Rows.CollectionChanged += delegate(object sender, System.ComponentModel.CollectionChangeEventArgs e){};

            _ColumnHeaderColor1 = Color.White;
            _ColumnHeaderColor2 = ColorClass.GetBColor();
            _SelectedRowColor1  = Color.White;
            _SelectedRowColor2  = Color.FromArgb(171, 217, 254);
        }
Beispiel #8
0
        public override object Clone()
        {
            JMTreeGridNode r = (JMTreeGridNode)base.Clone();

            r.UniqueValue = -1;
            r._level      = this._level;
            r._grid       = this._grid;
            r._parent     = this.Parent;

            r._imageIndex = this._imageIndex;
            if (r._imageIndex == -1)
            {
                r.Image = this.Image;
            }

            r.IsExpanded = this.IsExpanded;
            //r.treeCell = new TreeGridCell();

            return(r);
        }
Beispiel #9
0
        internal protected virtual bool ExpandNode(JMTreeGridNode node)
        {
            if (!node.IsExpanded || this._virtualNodes)
            {
                ExpandingEventArgs exp = new ExpandingEventArgs(node);
                this.OnNodeExpanding(exp);

                if (!exp.Cancel)
                {
                    this.LockVerticalScrollBarUpdate(true);
                    this.SuspendLayout();
                    _inExpandCollapse = true;
                    node.IsExpanded   = true;


                    foreach (JMTreeGridNode childNode in node.Nodes)
                    {
                        Debug.Assert(childNode.RowIndex == -1, "Row is already in the grid.");

                        this.SiteNode(childNode);
                        //this.BaseRows.Insert(rowIndex + 1, childRow);
                        //childNode.Cells[0].Value = "child";
                    }

                    ExpandedEventArgs exped = new ExpandedEventArgs(node);
                    this.OnNodeExpanded(exped);
                    // Convert this to a specific NodeCell property
                    _inExpandCollapse = false;
                    this.LockVerticalScrollBarUpdate(false);
                    this.ResumeLayout(true);
                    this.InvalidateCell(node.Cells[0]);
                }

                return(!exp.Cancel);
            }
            else
            {
                // row is already expanded, so we didn't do anything.
                return(false);
            }
        }
Beispiel #10
0
        internal protected virtual void UnSiteNode(JMTreeGridNode node)
        {
            if (node.IsSited || node.IsRoot)
            {
                // remove child rows first
                foreach (JMTreeGridNode childNode in node.Nodes)
                {
                    this.UnSiteNode(childNode);
                }

                // now remove this row except for the root
                if (!node.IsRoot)
                {
                    base.Rows.Remove(node);
                    // Row isn't sited in the grid anymore after remove. Note that we cannot
                    // Use the RowRemoved event since we cannot map from the row index to
                    // the index of the expandable row/node.
                    node.UnSited();
                }
            }
        }
Beispiel #11
0
        internal protected virtual bool CollapseNode(JMTreeGridNode node)
        {
            if (node.IsExpanded)
            {
                CollapsingEventArgs exp = new CollapsingEventArgs(node);
                this.OnNodeCollapsing(exp);

                if (!exp.Cancel)
                {
                    this.LockVerticalScrollBarUpdate(true);
                    this.SuspendLayout();
                    _inExpandCollapse = true;
                    node.IsExpanded   = false;

                    foreach (JMTreeGridNode childNode in node.Nodes)
                    {
                        Debug.Assert(childNode.RowIndex != -1, "Row is NOT in the grid.");
                        this.UnSiteNode(childNode);
                    }

                    CollapsedEventArgs exped = new CollapsedEventArgs(node);
                    this.OnNodeCollapsed(exped);
                    // Convert this to a specific NodeCell property
                    _inExpandCollapse = false;
                    this.LockVerticalScrollBarUpdate(false);
                    this.ResumeLayout(true);
                    this.InvalidateCell(node.Cells[0]);
                }

                return(!exp.Cancel);
            }
            else
            {
                // row isn't expanded, so we didn't do anything.
                return(false);
            }
        }
Beispiel #12
0
        protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            JMTreeGridNode node = this.OwningNode;

            if (node == null)
            {
                return;
            }

            Image image = node.Image;

            if (this._imageHeight == 0 && image != null)
            {
                this.UpdateStyle();
            }

            // paint the cell normally
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);


            Rectangle glyphRect = new Rectangle(cellBounds.X + this.GlyphMargin, cellBounds.Y, INDENT_WIDTH, cellBounds.Height - 1);
            int       glyphHalf = glyphRect.Width / 2;


            int level = this.Level;


            //		for images of the same size (ImageLayout.None)
            if (image != null)
            {
                Point pp;
                if (_imageHeight > cellBounds.Height)
                {
                    pp = new Point(glyphRect.X + this.glyphWidth, cellBounds.Y + _imageHeightOffset);
                }
                else
                {
                    pp = new Point(glyphRect.X + this.glyphWidth, (cellBounds.Height / 2 - _imageHeight / 2) + cellBounds.Y);
                }

                // Graphics container to push/pop changes. This enables us to set clipping when painting
                // the cell's image -- keeps it from bleeding outsize of cells.
                System.Drawing.Drawing2D.GraphicsContainer gc = graphics.BeginContainer();
                {
                    graphics.SetClip(cellBounds);
                    graphics.DrawImageUnscaled(image, pp);
                }
                graphics.EndContainer(gc);
            }

            // Paint tree lines
            if (node._grid.ShowLines)
            {
                using (Pen linePen = new Pen(SystemBrushes.ControlDark, 1.0f))
                {
                    linePen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
                    bool isLastSibling  = node.IsLastSibling;
                    bool isFirstSibling = node.IsFirstSibling;
                    if (node.Level == 1)
                    {
                        // the Root nodes display their lines differently
                        if (isFirstSibling && isLastSibling)
                        {
                            // only node, both first and last. Just draw horizontal line
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.Right, cellBounds.Top + cellBounds.Height / 2);
                        }
                        else if (isLastSibling)
                        {
                            // last sibling doesn't draw the line extended below. Paint horizontal then vertical
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.Right, cellBounds.Top + cellBounds.Height / 2);
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2);
                        }
                        else if (isFirstSibling)
                        {
                            // first sibling doesn't draw the line extended above. Paint horizontal then vertical
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.Right, cellBounds.Top + cellBounds.Height / 2);
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.X + 4, cellBounds.Bottom);
                        }
                        else
                        {
                            // normal drawing draws extended from top to bottom. Paint horizontal then vertical
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.Right, cellBounds.Top + cellBounds.Height / 2);
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top, glyphRect.X + 4, cellBounds.Bottom);
                        }
                    }
                    else
                    {
                        if (isLastSibling)
                        {
                            // last sibling doesn't draw the line extended below. Paint horizontal then vertical
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.Right, cellBounds.Top + cellBounds.Height / 2);
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2);
                        }
                        else
                        {
                            // normal drawing draws extended from top to bottom. Paint horizontal then vertical
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.Right, cellBounds.Top + cellBounds.Height / 2);
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top, glyphRect.X + 4, cellBounds.Bottom);
                        }

                        // paint lines of previous levels to the root
                        JMTreeGridNode previousNode   = node.Parent;
                        int            horizontalStop = (glyphRect.X + 4) - INDENT_WIDTH;

                        while (!previousNode.IsRoot)
                        {
                            if (previousNode.HasChildren && !previousNode.IsLastSibling)
                            {
                                // paint vertical line
                                graphics.DrawLine(linePen, horizontalStop, cellBounds.Top, horizontalStop, cellBounds.Bottom);
                            }
                            previousNode   = previousNode.Parent;
                            horizontalStop = horizontalStop - INDENT_WIDTH;
                        }
                    }
                }
            }

            if (node.HasChildren || node._grid.VirtualNodes)
            {
                // Paint node glyphs
                if (node.IsExpanded)
                {
                    graphics.DrawImage(JMControlsEx.Properties.Resources.cl, new Rectangle(glyphRect.X, glyphRect.Y + (glyphRect.Height / 2) - 4, 10, 10));
                }
                //node._grid.rOpen.DrawBackground(graphics, new Rectangle(glyphRect.X, glyphRect.Y + (glyphRect.Height / 2) - 4, 10, 10));
                else
                {
                    graphics.DrawImage(JMControlsEx.Properties.Resources.ex, new Rectangle(glyphRect.X, glyphRect.Y + (glyphRect.Height / 2) - 4, 10, 10));
                }
                //node._grid.rClosed.DrawBackground(graphics, new Rectangle(glyphRect.X, glyphRect.Y + (glyphRect.Height / 2) - 4, 10, 10));
            }
        }
Beispiel #13
0
        internal protected virtual void SiteNode(JMTreeGridNode node)
        {
            // Raise exception if parent node is not the root or is not sited.
            int            rowIndex = -1;
            JMTreeGridNode currentRow;

            node._grid = this;

            if (node.Parent != null && node.Parent.IsRoot == false)
            {
                // row is a child
                Debug.Assert(node.Parent != null && node.Parent.IsExpanded == true);

                if (node.Index > 0)
                {
                    currentRow = node.Parent.Nodes[node.Index - 1];
                }
                else
                {
                    currentRow = node.Parent;
                }
            }
            else
            {
                // row is being added to the root
                if (node.Index > 0)
                {
                    currentRow = node.Parent.Nodes[node.Index - 1];
                }
                else
                {
                    currentRow = null;
                }
            }

            if (currentRow != null)
            {
                while (currentRow.Level >= node.Level)
                {
                    if (currentRow.RowIndex < base.Rows.Count - 1)
                    {
                        currentRow = base.Rows[currentRow.RowIndex + 1] as JMTreeGridNode;
                        Debug.Assert(currentRow != null);
                    }
                    else
                    {
                        // no more rows, site this node at the end.
                        break;
                    }
                }
                if (currentRow == node.Parent)
                {
                    rowIndex = currentRow.RowIndex + 1;
                }
                else if (currentRow.Level < node.Level)
                {
                    rowIndex = currentRow.RowIndex;
                }
                else
                {
                    rowIndex = currentRow.RowIndex + 1;
                }
            }
            else
            {
                rowIndex = 0;
            }


            Debug.Assert(rowIndex != -1);
            this.SiteNode(node, rowIndex);

            Debug.Assert(node.IsSited);
            if (node.IsExpanded)
            {
                // add all child rows to display
                foreach (JMTreeGridNode childNode in node.Nodes)
                {
                    // could use the more efficient SiteRow with index.
                    this.SiteNode(childNode);
                }
            }
        }
Beispiel #14
0
 public JMTreeGridNodeEventBase(JMTreeGridNode node)
 {
     this._node = node;
 }
Beispiel #15
0
 public CollapsingEventArgs(JMTreeGridNode node)
     : base()
 {
     this._node = node;
 }
Beispiel #16
0
 public CollapsedEventArgs(JMTreeGridNode node)
     : base(node)
 {
 }
Beispiel #17
0
 public ExpandedEventArgs(JMTreeGridNode node)
     : base(node)
 {
 }
Beispiel #18
0
 public ExpandingEventArgs(JMTreeGridNode node)
     : base()
 {
     this._node = node;
 }