コード例 #1
0
        private void InitGrid()
        {
            Columns = new ArrayList();
            Rows    = new ArrayList();

            OfferBookGrid grid = (OfferBookGrid)dataSource;

            // use reflection to discover all properties of the object
            foreach (DataGridViewColumn c in grid.Columns)
            {
                Columns.Add(c.Name);
            }

            foreach (OfferBookGridRow r in grid.Rows)
            {
                if (!r.IsGroupRow && !r.IsNewRow)
                {
                    DataSourceRow row = new DataSourceRow(this, r);
                    for (int i = 0; i < Columns.Count; i++)
                    {
                        row.Add(r.Cells[i].Value);
                    }
                    Rows.Add(row);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// this function checks if the user hit the expand (+) or collapse (-) icon.
        /// if it was hit it will return true
        /// </summary>
        /// <param name="e">mouse click event arguments</param>
        /// <returns>returns true if the icon was hit, false otherwise</returns>
        internal bool IsIconHit(DataGridViewCellMouseEventArgs e)
        {
            if (e.ColumnIndex < 0)
            {
                return(false);
            }

            OfferBookGrid grid      = (OfferBookGrid)this.DataGridView;
            Rectangle     rowBounds = grid.GetRowDisplayRectangle(this.Index, false);
            int           x         = e.X;

            //DataGridViewColumn c = grid.Columns[e.ColumnIndex];
            //if (this.isGroupRow &&
            //    (c.DisplayIndex == 0) &&
            //    (x > rowBounds.Left + 4) &&
            //    (x < rowBounds.Left + 16) &&
            //    (e.Y > rowBounds.Height - 18) &&
            //    (e.Y < rowBounds.Height - 7))
            //    return true;

            DataGridViewColumn c;

            switch (((OfferBookGrid)this.DataGridView).Type)
            {
            case GridType.Buy:
                c = grid.Columns[e.ColumnIndex];
                if (this.isGroupRow &&
                    (c.DisplayIndex == 0) &&
                    (x > rowBounds.Left + 4) &&
                    (x < rowBounds.Left + 16) &&
                    (e.Y > rowBounds.Height - 18) &&
                    (e.Y < rowBounds.Height - 7))
                {
                    return(true);
                }
                break;

            case GridType.Sell:
                c = grid.Columns[e.ColumnIndex];
                if (this.isGroupRow &&
                    (c.DisplayIndex == 2) &&
                    (x > c.Width - 15) &&
                    (x < c.Width - 5) &&
                    (e.Y < rowBounds.Height - 7) &&
                    (e.Y > rowBounds.Height - 18))
                {
                    return(true);
                }
                break;
            }

            return(false);
        }
コード例 #3
0
        /// <summary>
        /// the main difference with a Group row and a regular row is the way it is painted on the control.
        /// the Paint method is therefore overridden and specifies how the Group row is painted.
        /// Note: this method is not implemented optimally. It is merely used for demonstration purposes
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="clipBounds"></param>
        /// <param name="rowBounds"></param>
        /// <param name="rowIndex"></param>
        /// <param name="rowState"></param>
        /// <param name="isFirstDisplayedRow"></param>
        /// <param name="isLastVisibleRow"></param>
        protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle rowBounds, int rowIndex, DataGridViewElementStates rowState, bool isFirstDisplayedRow, bool isLastVisibleRow)
        {
            if (this.isGroupRow)
            {
                OfferBookGrid grid = (OfferBookGrid)this.DataGridView;

                int rowHeadersWidth = grid.RowHeadersVisible ? grid.RowHeadersWidth : 0;

                // this can be optimized
                Color color  = base.DataGridView.AlternatingRowsDefaultCellStyle.BackColor;
                Brush brush  = new SolidBrush(grid.GroupHeaderBackColor);
                Brush brush2 = new SolidBrush(grid.GroupHeaderUnderlineColor);
                Brush brush3 = new SolidBrush(grid.GroupHeaderFontColor);

                int       gridwidth  = grid.Columns.GetColumnsWidth(DataGridViewElementStates.Displayed);
                Rectangle rowBounds2 = grid.GetRowDisplayRectangle(this.Index, true);

                // draw the background
                graphics.FillRectangle(brush, rowBounds.Left + rowHeadersWidth - grid.HorizontalScrollingOffset, rowBounds.Top, gridwidth, rowBounds.Height - 1);

                // draw text, using the current grid font
                string[] s          = group.Text.Split('|');
                SizeF    stringSize = new SizeF();

                stringSize = graphics.MeasureString(s[1], grid.GroupHeaderFont);

                // Não mostrar a corretora
                //graphics.DrawString(s[0], grid.GroupHeaderFont, brush3, grid.Columns[0].Width - stringSize.Width - 5, rowBounds.Bottom - 18);

                if (stringSize.Width > (grid.Columns[1].Width - 10))
                {
                    string texto = s[1].ToInt64().ToNumeroAbreviado();

                    stringSize = graphics.MeasureString(texto, grid.GroupHeaderFont);
                    graphics.DrawString(texto, grid.GroupHeaderFont, brush3, grid.Columns[0].Width + grid.Columns[1].Width - stringSize.Width - 5, rowBounds.Bottom - 18);
                }
                else
                {
                    switch (((OfferBookGrid)this.DataGridView).Type)
                    {
                    case GridType.Buy:
                        graphics.DrawString(s[1], grid.GroupHeaderFont, brush3, grid.Columns[0].Width + grid.Columns[1].Width - stringSize.Width - 5, rowBounds.Bottom - 18);
                        break;

                    case GridType.Sell:
                        graphics.DrawString(s[1], grid.GroupHeaderFont, brush3, grid.Columns[0].Width + 5, rowBounds.Bottom - 18);
                        break;
                    }
                }

                stringSize = graphics.MeasureString(s[2], grid.GroupHeaderFont);

                switch (((OfferBookGrid)this.DataGridView).Type)
                {
                case GridType.Buy:
                    graphics.DrawString(s[2], grid.GroupHeaderFont, brush3, grid.Columns[0].Width + grid.Columns[1].Width + grid.Columns[2].Width - stringSize.Width - 5, rowBounds.Bottom - 18);
                    break;

                case GridType.Sell:
                    graphics.DrawString(s[2], grid.GroupHeaderFont, brush3, rowBounds.Left + rowHeadersWidth - grid.HorizontalScrollingOffset + 4, rowBounds.Bottom - 18);
                    break;
                }

                //draw bottom line
                graphics.FillRectangle(brush2, rowBounds.Left + rowHeadersWidth - grid.HorizontalScrollingOffset, rowBounds.Bottom - 2, gridwidth - 1, 1);

                // draw right vertical bar
                if (grid.CellBorderStyle == DataGridViewCellBorderStyle.SingleVertical || grid.CellBorderStyle == DataGridViewCellBorderStyle.Single)
                {
                    graphics.FillRectangle(brush2, rowBounds.Left + rowHeadersWidth - grid.HorizontalScrollingOffset + gridwidth - 1, rowBounds.Top, 1, rowBounds.Height);
                }



                if (group.Collapsed)
                {
                    switch (((OfferBookGrid)this.DataGridView).Type)
                    {
                    case GridType.Buy:
                        if (grid.ExpandIcon != null)
                        {
                            graphics.DrawImage(grid.ExpandIcon, rowBounds.Left + rowHeadersWidth - grid.HorizontalScrollingOffset + 4, rowBounds.Bottom - 18, 11, 11);
                        }
                        break;

                    case GridType.Sell:
                        if (grid.ExpandIcon != null)
                        {
                            //graphics.DrawImage(grid.ExpandIcon, grid.Columns[0].Width + grid.Columns[1].Width + grid.Columns[2].Width - 15, rowBounds.Bottom - 18, 11, 11);
                            graphics.DrawImage(grid.ExpandIcon, rowBounds.Right - 15, rowBounds.Bottom - 18, 11, 11);
                        }
                        break;
                    }
                }
                else
                {
                    //if (grid.CollapseIcon != null)
                    //  Graphics.DrawImage(grid.CollapseIcon, rowBounds.Left + rowHeadersWidth - grid.HorizontalScrollingOffset + 4, rowBounds.Bottom - 18, 11, 11);

                    switch (((OfferBookGrid)this.DataGridView).Type)
                    {
                    case GridType.Buy:
                        if (grid.ExpandIcon != null)
                        {
                            graphics.DrawImage(grid.CollapseIcon, rowBounds.Left + rowHeadersWidth - grid.HorizontalScrollingOffset + 4, rowBounds.Bottom - 18, 11, 11);
                        }
                        break;

                    case GridType.Sell:
                        if (grid.ExpandIcon != null)
                        {
                            graphics.DrawImage(grid.CollapseIcon, rowBounds.Right - 15, rowBounds.Bottom - 18, 11, 11);
                        }
                        break;
                    }
                }

                brush.Dispose();
                brush2.Dispose();
                brush3.Dispose();
            }

            base.Paint(graphics, clipBounds, rowBounds, rowIndex, rowState, isFirstDisplayedRow, isLastVisibleRow);
        }