예제 #1
0
        public TreeGridAdvancedNode AddNode(TreeGridAdvancedNode parent, TreeGridRow xrow, bool addexpanded)
        {
            if (parent == null)
            {
                parent = MainNode;
                //throw new Exception("Node must have parent, use grid.MainNode instead");
            }
            rowid_generator++;
            TreeGridAdvancedNode newnode = new TreeGridAdvancedNode();

            newnode.RowId    = rowid_generator;
            newnode.Parent   = parent;
            newnode.Level    = parent.Level + 1;
            xrow.ChildIndex  = parent.Childs.Count;
            xrow.NodeId      = rowid_generator;
            xrow.Level       = newnode.Level;
            xrow.IsRoot      = newnode.Level == 0;
            xrow.Parent      = parent.Row;
            xrow.Node        = newnode;
            newnode.Expanded = addexpanded;
            newnode.Row      = xrow;
            newnode.Grid     = this;

            if (FMaxLevel < newnode.Level)
            {
                FMaxLevel = newnode.Level;
            }
            AllRows.Add(rowid_generator, newnode);
            parent.Childs.Add(newnode);
            return(newnode);
        }
예제 #2
0
        public TreeGridAdvancedNode AddNode(TreeGridAdvancedNode parent, object[] nvalues, bool addexpanded)
        {
            TreeGridRow nrow = new TreeGridRow();

            nrow.CreateCells(this, nvalues);

            return(AddNode(parent, nrow, addexpanded));
        }
예제 #3
0
        public void ClickNode(TreeGridRow nrow)
        {
            TreeGridAdvancedNode nnode = ((TreeGridAdvanced)(nrow.DataGridView)).FindNode(nrow);

            if (nnode.Expanded)
            {
                nnode.Contract();
            }
            else
            {
                nnode.Expand();
            }
        }
예제 #4
0
 protected override void OnMouseDown(DataGridViewCellMouseEventArgs e)
 {
     if (e.Location.X > this.InheritedStyle.Padding.Left)
     {
         base.OnMouseDown(e);
     }
     else
     {
         TreeGridRow            nrow = (TreeGridRow)this.DataGridView.Rows[this.RowIndex];
         TreeGridAdvancedColumn ncol = (TreeGridAdvancedColumn)DataGridView.Columns[ColumnIndex];
         ncol._ismousecap = true;
     }
 }
예제 #5
0
        protected override void OnMouseUp(DataGridViewCellMouseEventArgs e)
        {
            base.OnMouseUp(e);

            TreeGridRow            nrow = (TreeGridRow)this.DataGridView.Rows[this.RowIndex];
            TreeGridAdvancedColumn ncol = (TreeGridAdvancedColumn)DataGridView.Columns[ColumnIndex];

            if (ncol._ismousecap)
            {
                ncol._ismousecap = false;
                ncol.ClickNode(nrow);
            }
        }
예제 #6
0
        public void Expand()
        {
            if (Expanded)
            {
                return;
            }
            int index = Grid.Rows.IndexOf(Row);

            if (index >= 0)
            {
                TreeGridRow[] xrows = new TreeGridRow[Childs.Count];
                for (int i = 0; i < Childs.Count; i++)
                {
                    xrows[i] = Childs[i].Row;
                }
                Grid.Rows.InsertRange(index + 1, xrows);
            }
            Expanded = true;
        }
예제 #7
0
        public bool FindTextNode(TreeGridRow nnode, string busca, int firstcolumn, int lastcolumn, bool searchchild)
        {
            bool found = false;

            for (int i = firstcolumn; i <= lastcolumn; i++)
            {
                if (Columns[i].Visible)
                {
                    string           nvalue   = "";
                    DataGridViewCell nextcell = nnode.Cells[i];
                    if (nextcell.Value != null)
                    {
                        nvalue = nextcell.Value.ToString().ToUpper().Replace(',', '.');
                    }
                    if (nvalue.IndexOf(busca) >= 0)
                    {
                        found = true;
                        // Expand all parents
                        if (nnode.Node.Parent != null)
                        {
                            nnode.Node.Parent.Expand();
                        }
                        //ExpandParent(nnode, null);
                        CurrentCell = nnode.Cells[i];
                        FirstDisplayedScrollingColumnIndex = CurrentCell.ColumnIndex;
                        break;
                    }
                }
            }
            if ((!found) && (searchchild))
            {
                foreach (TreeGridAdvancedNode childnoder in nnode.Node.Childs)
                {
                    found = FindTextNode(childnoder.Row, busca, 0, Columns.Count - 1, true);
                    if (found)
                    {
                        break;
                    }
                }
            }

            return(found);
        }
예제 #8
0
        public void FindText(string ntext)
        {
            if (CurrentCell == null)
            {
                return;
            }
            // Busca desde la celda seleccionada hacia la derecha y abajo
            string busca = ntext.ToUpper().Replace(',', '.');

            if (busca.Length == 0)
            {
                return;
            }
            TreeGridRow currnode = (TreeGridRow)CurrentRow;
            int         ncolumn  = CurrentCell.ColumnIndex + 1;
            bool        found    = false;

            for (int i = currnode.Index; i < Rows.Count; i++)
            {
                found = FindTextNode((TreeGridRow)Rows[i], busca, ncolumn, Columns.Count - 1, true);
                if (found)
                {
                    break;
                }
                ncolumn = 0;
            }
            if (!found)
            {
                for (int i = 0; i < currnode.Index; i++)
                {
                    found = FindTextNode((TreeGridRow)Rows[i], busca, 0, Columns.Count - 1, true);
                    if (found)
                    {
                        break;
                    }
                }
                if (!found)
                {
                    FindTextNode(currnode, busca, 0, CurrentCell.ColumnIndex - 1, false);
                }
            }
        }
예제 #9
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)
        {
            if (!paddingok)
            {
                PrepareDraw();
                cellStyle.Padding = Style.Padding;
            }

            DataGridViewRow xrow = this.DataGridView.Rows[rowIndex];

            if (!(xrow is TreeGridRow))
            {
                return;
            }
            TreeGridRow node = (TreeGridRow)xrow;

            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);

            // TODO: Indent width needs to take image size into account
            Rectangle glyphRect = new Rectangle(cellBounds.X + this.GlyphMargin, cellBounds.Y, INDENT_WIDTH, cellBounds.Height - 1);
            int       glyphHalf = glyphRect.Width / 2;

            //TODO: This painting code needs to be rehashed to be cleaner
            int level = this.Level;

            //TODO: Rehash this to take different Imagelayouts into account. This will speed up drawing
            //		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 (((TreeGridAdvanced)(DataGridView)).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
                        TreeGridRow previousNode   = node.Parent;
                        int         horizontalStop = (glyphRect.X + 4) - INDENT_WIDTH;

                        if (previousNode != null)
                        {
                            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 (previousNode == null)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            if (node.HasChildren)
            {
                TreeGridAdvanced _grid = (TreeGridAdvanced)DataGridView;
                // Paint node glyphs
                if (node.Node.Expanded)
                {
                    if (_grid.themesenabled)
                    {
                        try
                        {
                            if (_grid.rOpen == null)
                            {
                                _grid.rOpen        = new VisualStyleRenderer(VisualStyleElement.TreeView.Glyph.Opened);
                                _grid.treeboxwidth = System.Convert.ToInt32(WinFormsGraphics.DPIScale * 10);
                            }
                            _grid.rOpen.DrawBackground(graphics, new Rectangle(glyphRect.X, glyphRect.Y + (glyphRect.Height / 2) - 4,
                                                                               _grid.treeboxwidth, _grid.treeboxwidth));

                            /*
                             * Pen npen = Pens.Black;
                             * int recwidth = 8;
                             * int margin = 2;
                             * int leftmargin = -recwidth / 2 - 2;
                             * int topmargin = 0;
                             * Rectangle nrect = new Rectangle(leftmargin + glyphRect.X + glyphRect.Width / 2 - recwidth / 2,
                             *                              topmargin + glyphRect.Y + glyphRect.Height / 2 - recwidth / 2,
                             *                              recwidth,
                             *                              recwidth);
                             * graphics.DrawLine(npen, new Point(nrect.X + margin, nrect.Top + recwidth / 2),
                             *                      new Point(nrect.X + recwidth - margin, nrect.Top + recwidth / 2));*/
                        }
                        catch
                        {
                            _grid.themesenabled = false;
                        }
                    }
                    if (!_grid.themesenabled)
                    {
                        Pen       npen       = Pens.Black;
                        int       recwidth   = 8;
                        int       margin     = 2;
                        int       leftmargin = -recwidth / 2 - 2;
                        int       topmargin  = 0;
                        Rectangle nrect      = new Rectangle(leftmargin + glyphRect.X + glyphRect.Width / 2 - recwidth / 2,
                                                             topmargin + glyphRect.Y + glyphRect.Height / 2 - recwidth / 2,
                                                             recwidth,
                                                             recwidth);
                        using (Brush nbrush = new SolidBrush(cellStyle.BackColor))
                        {
                            graphics.FillRectangle(nbrush, nrect);
                            graphics.DrawRectangle(npen, nrect);
                            graphics.DrawLine(npen, new Point(nrect.X + margin, nrect.Top + recwidth / 2),
                                              new Point(nrect.X + recwidth - margin, nrect.Top + recwidth / 2));
                        }
                    }
                }
                else
                {
                    if (_grid.themesenabled)
                    {
                        try
                        {
                            if (_grid.rClosed == null)
                            {
                                _grid.rClosed      = new VisualStyleRenderer(VisualStyleElement.TreeView.Glyph.Closed);
                                _grid.treeboxwidth = System.Convert.ToInt32(WinFormsGraphics.DPIScale * 10);
                            }
                            //    node._grid.rClosed = new VisualStyleRenderer("Explorer::TreeView",2,1);
                            _grid.rClosed.DrawBackground(graphics, new Rectangle(glyphRect.X, glyphRect.Y + (glyphRect.Height / 2) - 4, _grid.treeboxwidth, _grid.treeboxwidth));
                        }
                        catch
                        {
                            _grid.themesenabled = false;
                        }
                    }
                    if (!_grid.themesenabled)
                    {
                        Pen npen       = Pens.Black;
                        int recwidth   = 8;
                        int margin     = 2;
                        int leftmargin = -recwidth / 2 - 2;
                        int topmargin  = 0;
                        using (Brush nbrush = new SolidBrush(cellStyle.BackColor))
                        {
                            Rectangle nrect = new Rectangle(leftmargin + glyphRect.X + glyphRect.Width / 2 - recwidth / 2,
                                                            topmargin + glyphRect.Y + glyphRect.Height / 2 - recwidth / 2,
                                                            recwidth,
                                                            recwidth);
                            graphics.FillRectangle(nbrush, nrect);
                            graphics.DrawRectangle(npen, nrect);
                            graphics.DrawLine(npen, new Point(nrect.X + margin, nrect.Top + recwidth / 2),
                                              new Point(nrect.X + recwidth - margin, nrect.Top + recwidth / 2));
                            graphics.DrawLine(npen, new Point(nrect.X + recwidth / 2, nrect.Top + margin),
                                              new Point(nrect.X + recwidth / 2, nrect.Top + recwidth - margin));
                        }
                    }
                }
            }
        }
예제 #10
0
        public TreeGridAdvancedNode FindNode(TreeGridRow nrow)
        {
            long aindex = (long)nrow.NodeId;

            return(AllRows[aindex]);
        }