在DatagridView中隐藏标题复选框

时间:2016-07-15 21:05:43

标签: c# winforms

我有一个要求,我需要在datagaridview的第一列中有复选框列。因此,当我添加复选框时,它也会在同一列的标题中添加相同的内容。我不需要此标题复选框。我想隐藏它。我无法做到这一点。我曾尝试过Cell painitng技术,但它不适合我:( ..请帮忙

                        ckBox = new CheckBox();
                        ckBox.Size = new Size(14, 14);
                        //Get the column header cell bounds
                        Rectangle rect = dgv_CourseList.GetCellDisplayRectangle(0,-1, true);
                        Point oPoint = new Point();
                        oPoint.X = rect.Location.X + 3;
                        oPoint.Y = rect.Location.Y + 2;

//check only for cells of first column and only header
        if (this.dgv_CourseList.Columns[0].Index == e.ColumnIndex && e.RowIndex < 0)
        {

                // You can change e.CellStyle.BackColor to Color.Gray for example
                using (Brush backColorBrush = new SolidBrush(e.CellStyle.BackColor))
                {
                    // Erase the cell.
                    e.Graphics.FillRectangle(backColorBrush, e.CellBounds);
                    e.Handled = true;
                }
            //}
        }
    }

0 个答案:

没有答案