Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Color of Button in DataGridView Cell

I have a large DataGridView control that has several cells most of which contain a button. How can I change the color of those buttons?

This changes the "outline" of the button but not the button itself.

row.Cells[2].Style.BackColor = System.Drawing.Color.Red;

This doesn't seem to change anything that's visible:

row.Cells[2].Style.ForeColor = System.Drawing.Color.Red;

If it's not possible to change the background, is it possible to change the font on the button?

Using .NET 2.0.

like image 442
Dave Avatar asked Feb 25 '09 16:02

Dave


1 Answers

The default button in a DataGridView is drawn using the ButtonRenderer which makes it quite difficult to override. if I were you, I'd just set the button FlatStyle to "Popup".

DataGridViewButtonCell buttonCell = (DataGridViewButtonCell)dataGridMappings.Rows[0].Cells[0];
buttonCell.FlatStyle = FlatStyle.Popup;
buttonCell.Style.BackColor = System.Drawing.Color.Red;
like image 71
NTDLS Avatar answered Sep 20 '22 09:09

NTDLS