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.
Unfortunately, activation email could not send to your email. Please try again.

Specify Color of PushButton on a cell of Grid

Thread ID:





52370 Nov 27,2006 03:13 PM Nov 27,2006 11:38 PM Windows Forms 1
Tags: GridControl
Asked On November 27, 2006 03:13 PM


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;

Himanshu Kumar

Administrator [Syncfusion]
Replied On November 27, 2006 11:38 PM

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.

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.

Let me know if this helps.
Best Regards,


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.