Esempio n. 1
0
        protected override void OnRowPostPaint(DataGridViewRowPostPaintEventArgs e)
        {
            base.OnRowPostPaint(e);
            Rectangle cellRectangle = new Rectangle
                                          (e.RowBounds.Location.X, e.RowBounds.Location.Y, this.RowHeadersWidth, this.Rows[e.RowIndex].Height);

            using (SolidBrush brush = new SolidBrush(SystemColors.ControlLight))
            {
                e.Graphics.FillRectangle(brush, cellRectangle);
            }
            ICollapseRow row = this.Rows[e.RowIndex] as ICollapseRow;

            if (row == null)
            {
                return;
            }
            if (row.SubRows != null && row.SubRows.Count != 0)
            {
                Rectangle rect = new Rectangle(e.RowBounds.Location.X + 4, e.RowBounds.Location.Y + 5, 9, 9);
                Image     img  = null;
                if (row.IsCollapse)
                {
                    img = IconsLibrary.Plus;
                }
                else
                {
                    img = IconsLibrary.Minus;
                }
                e.Graphics.DrawImage(img, rect);
            }
        }
        /// <summary>
        /// 不要直接调用
        /// 通过设置 IsCollapse 属性来获得相应的功能
        /// </summary>
        private void HideSubRow()
        {
            if (this.SubRows == null || this.SubRows.Count == 0)
            {
                return;
            }

            this.DataGridView.SuspendLayout();

            for (int i = 0; i < this.SubRows.Count; i++)
            {
                if (this.SubRows[i].DataGridView == this.DataGridView)
                {
                    //首先处理可能的子行和子行的子行]
                    ICollapseRow collapseRow = this.SubRows[i] as ICollapseRow;
                    if (collapseRow != null)
                    {
                        collapseRow.IsCollapse = true;
                    }

                    this.DataGridView.Rows.Remove(this.SubRows[i]);
                }
            }

            this.DataGridView.ResumeLayout();
        }
Esempio n. 3
0
        protected override void OnCellMouseDoubleClick(DataGridViewCellMouseEventArgs e)
        {
            base.OnCellMouseDoubleClick(e);
            ICollapseRow row = this.Rows[e.RowIndex] as ICollapseRow;

            if (row != null)
            {
                row.IsCollapse = !row.IsCollapse;
            }
        }