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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

[GDBG]How to Change Cell BackColor when CurrentCellChanged

Thread ID:

Created:

Updated:

Platform:

Replies:

93418 Mar 12,2010 03:50 AM UTC Mar 26,2010 04:03 AM UTC ASP.NET Web Forms (Classic) 4
loading
Tags: GridGroupingControl
Chen Chi Chang
Asked On March 12, 2010 03:50 AM UTC

When I changed the text of a cell on UI,
I would like to be to change the cell's BackColor,
How can I really be done?

Thanks a lot.

Rajadurai C [Syncfusion]
Replied On March 18, 2010 01:27 PM UTC

Hi Chen,

Thanks for your interest in Syncfusion Products.

In GridDataBoundGrid, the only thing stored on a cell by cell basis is the value (that is mapped to the DataSource, so grid does not actually hold this information either). Hence, you cannot use indexers on the GridDataBoundGrid to set any property other than CellValue (or Text as they are the same thing) as shown below.

this.gridDataBoundGrid1[0,2].BackColor = Color.BurlyWood;

To change a cell specific property, you should handle the PrepareViewStyleInfo event, and there check e.ColIndex and e.RowIndex, if they point to the respective cells and apply styles accordingly.

void gridDataBoundGrid1_PrepareViewStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs e)
{
if (e.RowIndex == 3 && e.ColIndex == 3)
e.Style.BackColor = Color.BurlyWood;
}

To set backcolor based on change happened in cell, you need to get the rowindex and columnindex of the currentcell from the CurrentCellChanged event and check it in the PrepareViewStyleInfo event, if it is the queried cell and set backcolor accordingly. Here is the code that can be handled.

if (e.RowIndex == rowIndex && e.ColIndex == colIndex)
e.Style.BackColor = Color.Red;
else
{
e.Style.BackColor = SystemColors.Window;
rowIndex = -1;
colIndex = -1;
}

Here rowIndex, colIndex values are retrieved through CurrentCellChanged event.

Regards,
Rajadurai

Chen Chi Chang
Replied On March 23, 2010 03:29 AM UTC

Hi Rajadurai,
Thanks for your reply. Now I can change cell's BackColor by your method.
But it is not a permanent change.
I mean GDBG[1,3](already have changed its color) will change back to SystemColors when GDBG[1,4] change to red.
And when I highlighted this row, the color-changed cell turned back to SystemColors.

How could we change cell's color 'permanently'?

Thanks again.
Best Regards, Chen.

Chen Chi Chang
Replied On March 23, 2010 03:49 AM UTC

Hi Rajadurai,
I already find out where the question is. I must store Row Index and Col Index of all the color-changed cell with a list.
Then always check the list and change the BackColor in PrepareViewStyleInfo.

Thanks for your reply again.
Best Regards, Chen.

Rajadurai C [Syncfusion]
Replied On March 26, 2010 04:03 AM UTC

Hi Chen,

Thanks for your update.

Yes. In such cases, it is needed to retain the cell indexes in a collection and use the same in PrepareViewStyleInfo event to retain the backcolor. Glad to hear that you had got it working.

Thank you for using Syncfusion Products.

Regards,
Rajadurai

CONFIRMATION

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.

Warning Icon 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.Close Icon

;