If I have a grid control that has a cell whose cell type is pushbutton, how do I set the color of the button''s background (& it''s font for that matter)? I tried using:
MyGrid[r,c].CellType = PushButton;
MyGridr,c].CellAppearance = GridCellAppearance.Raised;
GridStyleInfo gsi = new GridStyleInfo();
gsi.BackColor = Color.AliceBlue;
But this approach seems to be ignored. the button is always grey.
Our PushButton uses ControlPaint.DrawButton to draw the button, and this method does not support background coloring (other than what you might get from a Themed OS.). So, for now, there is no property setting that you can use to handle this.
Some ways around this would be to add a Windows Forms PushButton (which does accept a backcolor) to a cell using the Control celltype. This would only be useful if you had 1 or 2 cells where you wanted to see this button. Here is a little sample.
If you needed to have this button in a lot of cells, you would have to derive a custom button to handle this. You could either do a bitmap button like the one shown in grid\samples\in depth\cellbuttons or you could derive a cell control like the grid\samples\cellstypes\calendarcell but using a Windows Forms PushButton instead of the calendar.
JBJohn BowmDecember 4, 2004 02:05 PM UTC
Thanks for the help/ideas (btw, why are you answering this on Sat? ). I''ve been trying to work w/ the CellButtons example, but not yet able to customize it to what I''d like and make it work. I may just not waste any time and live w/ the std grey color on the built in PushButton type because I don''t have much time to iron this out.
AdministratorDecember 5, 2004 10:01 PM UTC
Another way you can do this is to handle the DrawCellButtonBackground event. Here is a sample.
JBJohn BowmDecember 7, 2004 07:32 PM UTC
Thanks again for the example code. It may just work out better for the way we need it to behave.