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.

Conditional Format of Row

Thread ID:

Created:

Updated:

Platform:

Replies:

73602 May 12,2008 04:03 PM May 20,2008 12:04 AM ASP.NET Web Forms (Classic) 3
loading
Tags: GridGroupingControl
David A. Gonzales
Asked On May 12, 2008 04:03 PM

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.


Janagan [Syncfusion]
Replied On May 16, 2008 06:47 AM

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.




David A. Gonzales
Replied On May 16, 2008 12:59 PM

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.


Janagan [Syncfusion]
Replied On May 20, 2008 12:04 AM

Hi David,

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

Regards,
Janagan.


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.

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.

;