如题
如何修改datagridview内定义为DataGridViewButtonColumn列的按钮的背景色 不是Cell的背景色

解决方案 »

  1.   

    使用
    DataGridViewColumns.FindControl("按钮ID")来获取按钮,然后可以随意改变它的样式
      

  2.   

    单元格样式只能设置cell的背景色 我是想改变cell中 button的背景色
      

  3.   


      private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
            {
                if (e.ColumnIndex == 2)
                {
                    e.Handled = true;
                    
                    using (SolidBrush brush = new SolidBrush(Color.Red))
                    {
                        e.Graphics.FillRectangle(brush, e.CellBounds);
                    }
                    ControlPaint.DrawBorder(e.Graphics, e.CellBounds, Color.Yellow, ButtonBorderStyle.Outset);
                }
            }由于DataGridView的Button列是由Graphics绘制上去的,而不是真正的Button控件。所以绘制出来不是很好看,不过button的背景色是改了
      

  4.   

    那这样的话 是不是button上面的文字就会被覆盖 不会显示文字了