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

GridConditionalFormatDescriptor - how to format single cell?

Hi,

Is there any way GridConditionalFormatDescriptor can be used to format a single cell instead of the whole row?

Thanks,

Julien


1 Reply

SR SubhaSheela R Syncfusion Team August 29, 2008 12:21 PM UTC

Hi Julien,

Thanks for using Syncfusion Products.

GridConditionalFormatDescriptor only allow you to row formatting. If you want to format any one cell, then you need to use QueryCellStyleInfo or PrepareViewStyleInfo event to achieve that. Below is the example that shows to change backcolor of a negative value cell and bracket for nagative value cell. Please refer to the below code in which QueryCellStyleInfo event is used to achieve your need.


this.gridGroupingControl1.QueryCellStyleInfo += new GridTableCellStyleInfoEventHandler(gridGroupingControl1_QueryCellStyleInfo);
void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
if (e.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell
|| e.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell)
{
if (e.TableCellIdentity.Column.MappingName == "B")
{
int cellvalue = Convert.ToInt32(e.Style.CellValue);
if (cellvalue < 0)
{
e.Style.BackColor = Color.Red;
e.Style.Format = "{#,##}"; // You can set your own format
}
}
}
}


Please refer to the sample given below which illustrates the above:

http://websamples.syncfusion.com/samples/Grid.Windows/I41286/main.htm

Please let me know if you have any question.

Regards,
Subhasheela R





Loader.
Live Chat Icon For mobile
Up arrow icon