Exemple #1
0
        private void FillGrid1b(OutlookGrid dgw, List <Dati> Lista)
        {
            dgw.BindData(null, null);
            dgw.Rows.Clear();
            dgw.Columns.Clear();
            // dgw.Columns.Add("TC", "");

            //dgw.Columns.Add(new DataGridViewTextBoxColumn() {HeaderText="Tipo",Name="Tipo", CellTemplate = new MyDataGridViewTextBoxCell() });
            dgw.Columns.Add("Tipo", "Tipo");
            dgw.Columns.Add("Name", "Name");
            dgw.Columns.Add("DisplayName", "Display Name");
            dgw.Columns.Add("DisplayVersion", "Display Version");
            dgw.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            //dgw.Columns["TC"].Width = 10; dgw.Columns["TC"].AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
            dgw.Columns["Tipo"].Width = 40; dgw.Columns["Tipo"].AutoSizeMode = DataGridViewAutoSizeColumnMode.None; dgw.Columns["Tipo"].AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
            dgw.Columns["Tipo"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgw.Columns["Name"].FillWeight           = 27;
            dgw.Columns["DisplayName"].FillWeight    = 39;
            dgw.Columns["DisplayVersion"].FillWeight = 27;

            foreach (Dati riga in Lista)
            {
                dgw.Rows.Add();
                dgw.Rows[dgw.RowCount - 1].Cells["Tipo"].Value           = riga.Tipo;
                dgw.Rows[dgw.RowCount - 1].Cells["Name"].Value           = riga.GUID;
                dgw.Rows[dgw.RowCount - 1].Cells["DisplayName"].Value    = riga.DisplayName;
                dgw.Rows[dgw.RowCount - 1].Cells["DisplayVersion"].Value = riga.DisplayVersion;
            }
        }
    /// <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);
        }

        OutlookGrid grid      = (OutlookGrid)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);
        }

        return(false);


        //System.Diagnostics.Debug.WriteLine(e.ColumnIndex);
    }
    /// <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)
        {
            OutlookGrid grid            = (OutlookGrid)this.DataGridView;
            int         rowHeadersWidth = grid.RowHeadersVisible ? grid.RowHeadersWidth : 0;

            // this can be optimized
            Brush brush  = new SolidBrush(grid.DefaultCellStyle.BackColor);
            Brush brush2 = new SolidBrush(Color.FromKnownColor(KnownColor.GradientActiveCaption));

            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
            graphics.DrawString(group.Text, grid.Font, Brushes.Black, rowHeadersWidth - grid.HorizontalScrollingOffset + 23, rowBounds.Bottom - 18);

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

            // 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)
            {
                if (grid.ExpandIcon != null)
                {
                    graphics.DrawImage(grid.ExpandIcon, rowBounds.Left + rowHeadersWidth - grid.HorizontalScrollingOffset + 4, rowBounds.Bottom - 18, 11, 11);
                }
            }
            else
            {
                if (grid.CollapseIcon != null)
                {
                    graphics.DrawImage(grid.CollapseIcon, rowBounds.Left + rowHeadersWidth - grid.HorizontalScrollingOffset + 4, rowBounds.Bottom - 18, 11, 11);
                }
            }
            brush.Dispose();
            brush2.Dispose();
        }
        base.Paint(graphics, clipBounds, rowBounds, rowIndex, rowState, isFirstDisplayedRow, isLastVisibleRow);
    }
    private void InitGrid()
    {
        OutlookGrid grid = (OutlookGrid)dataSource;

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

        foreach (OutlookGridRow 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);
            }
        }
    }