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

Conditional Format of Row

Hi,
I was wondering if it's possible to use the GridConditionalFormatDescriptor expression but instead of formatting the whole row just certain columns? I would like to do something like "if the percentage value [Percent_Value] is greater than 90% then set the Result [Result] column to the color Red":

gcfd1.Expression = "[Percent_Value] > 90";

then only format column [Result] to red.

I can use the GridGroupingControl1_QueryCellStyleInfo event and handle the colIndex and rowIndex but it's not very general in nature.

Maybe something like:

Color c1 = Color.FromName("Red");
gcfd1.Appearance.Column["Result"].TextColor = c1;
gcfd1.Appearance.Column["Result"].Font.Bold = true;

if that is possible?

Thanks.
David.


3 Replies

JA Janagan Syncfusion Team May 16, 2008 10:47 AM UTC

Hi David,

Thanks for posting your query to us.

I regret to let you know that the formatting of specific cells based on conditions can be achieved only through QueryCellStyleInfo event. But you can apply format based on conditions for the entire row. Please refer the following code snippet:



protected void Page_Load(object sender, EventArgs e)
{
GridConditionalFormatDescriptor gcfd1 = new GridConditionalFormatDescriptor();

gcfd1.Expression= "[CategoryID]<2";

gcfd1.Appearance.AnyRecordFieldCell.BackColor = System.Drawing.Color.Red;
this.GridGroupingControl1.TableDescriptor.ConditionalFormats.Add(gcfd1);

}

To apply format for specific column:

protected void GridGroupingControl1_QueryCellStyleInfo1(object sender, GridTableCellStyleInfoEventArgs e)
{

if ((e.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell || e.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell))
{



if (e.TableCellIdentity.Column.Name == "CategoryID")
{

val1 = (System.Int32)e.Style.CellValue;


}
if (e.TableCellIdentity.Column.Name == "SupplierID")
{
val2 = (System.Int32)e.Style.CellValue;
}
if ((val2 < val1)&&(e.TableCellIdentity.Column.Name == "CategoryID"))

e.Style.TextColor = System.Drawing.Color.Magenta;


}


}



Please refer the sample in the link below which illustrates the above:

http://websamples.syncfusion.com/samples/Grid.Web/6.2.0.40/Grid_ASP_format/main.htm


Please try running the sample and let me know if this helps.

Thanks,
Janagan.





DA David A. Gonzales May 16, 2008 04:59 PM UTC

Thanks. I am using the QueryCellStyleInfo to handle this situation. We are just defining the cells that need to be updated elsewhere and then while the QueryCellStyleInfo is called we determine whether the cell needs to be formated or not. Just an extra step but not too bad.

David.



JA Janagan Syncfusion Team May 20, 2008 04:04 AM UTC

Hi David,

Thanks for the update. Please let me know if you have any other questions.

Regards,
Janagan.


Loader.
Live Chat Icon For mobile
Up arrow icon