Change Color of Button in DataGridView Cell
I missed Dave's note on Tomas' answer so i am just posting the simple solution to this.
Update the FlatStyle property of the Button column to Popup and then by updating the backcolor and forecolor you can change the appearance of the button.
DataGridViewButtonColumn c = (DataGridViewButtonColumn)myGrid.Columns["colFollowUp"];
c.FlatStyle = FlatStyle.Popup;
c.DefaultCellStyle.ForeColor = Color.Navy;
c.DefaultCellStyle.BackColor = Color.Yellow;
As per MSDN:
When visual styles are enabled, the buttons in a button column are painted using a ButtonRenderer, and cell styles specified through properties such as DefaultCellStyle have no effect.
Therefore, you have one of two choices. In your Program.cs you can remove this line:
Application.EnableVisualStyles();
which will make it work, but make everything else look like crap. Your other option, and you're not going to like this one, is to inherit from DataGridViewButtonCell and override the Paint() method. You can then use the static method on the ButtonRenderer class called DrawButton, to paint the button yourself. That means figuring out which state the cell currently is in (clicked, hover etc.) and painting the corners and borders etc... You get the idea, it's doable, but a HUGE pain.
If you want to though, here's just some sample code to get you started:
//Custom ButtonCell
public class MyButtonCell : DataGridViewButtonCell
{
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
{
ButtonRenderer.DrawButton(graphics, cellBounds, formattedValue.ToString(), new Font("Comic Sans MS", 9.0f, FontStyle.Bold), true, System.Windows.Forms.VisualStyles.PushButtonState.Default);
}
}
Then here's a test DataGridView:
DataGridViewButtonColumn c = new DataGridViewButtonColumn();
c.CellTemplate = new MyButtonColumn();
this.dataGridView1.Columns.Add(c);
this.dataGridView1.Rows.Add("Click Me");
All this sample does, is paint a button with the font being "Comic Sans MS". It doesn't take into account the state of the button as you'll see when you run the app.
GOOD LUCK!!