We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Specify Color of PushButton on a cell of Grid

Hi,

I have been trying to solve this issue for quite some time.

I have a SuncFusion Grid Control.

I am creating a distict button in each cell of the grid.

I am able to set some properties like CellType,CellAppearance and Description.

However, I am unable to figure out how to specify the color of the PushButton.

If we say something like GridControl[RowIndex,ColIndex].BackColor, then it defines the color of the cell per se and not the PushButton.

One approach is to define a PushButton type calss and implement some method to specify the color.

However, I am sure there must be a much easier and direct way to implement the same.

Please advise.

Here is the code snippet:

for (j = 1 ; j <= gridCounter ; j++ )
{
syncGridControl[i,j].CellType = "PushButton";
syncGridControl[i,j].CellAppearance = GridCellAppearance.Raised;
syncGridControl[i,j].Description = arCatList[counter].ToString();
syncGridControl.CellButtonClicked +=new GridCellButtonClickedEventHandler(syncGridControl_CellButtonClicked);
counter = counter + 1;
}

Regards,
Himanshu Kumar

1 Reply

AD Administrator Syncfusion Team November 28, 2006 04:38 AM UTC

Hi Himanshu,

The BackColor of a cell is normally controlled through the style.BackColor property of the cell. This should work for any cell unless you are handling some event that prevents this default behavior. This should n't work for theme enabled header (RowHeader ,ColumnHeader) cells and PushButtons. You need to subscribe to the grid's TableControlDrawCell event for drawing the cells. There you can use e.Inner.Graphics.FillRectanlge to draw the backcolor and then set e.Inner.Cancel = true to indicate you have handled the drawing.

Here is a sample that shows how you can use this event to draw backcolor in cells.
ThemeTable_51a1976b.zip

One comment though is that the backcolor of buttons is not control through the style object for the cell. Instead, you will have to handle an event to color buttons.

Here is a forum thread discussing coloring buttons.
http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=26772

Let me know if this helps.
Best Regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon