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
close icon

Cell Style in a Grid Grouping Control

Hi,

I would like to color code the cell in a Grid Grouping control based on data in two different rows. See Attached file:

Here is what I want to do: In the following example if the price of Rice > $1.00 and Wheat > $2.00 then color the value of Rice as Red.

Company food prices ($)
----------------------------------
Company X Rice 2
Company X Wheat 3
Company X potates 1
Company X Bread 1.5
Company Y Rice 0.99
Company Y Wheat 2.5
Company Y potates 1
Company Y Bread 1.5
Company Z Rice 4
Company Z Wheat 3.5
Company Z potates 1
Company Z Bread 1.5


Thanks!

Rekha



Test_997692f0.zip

5 Replies

RS Rajarajeswari S Syncfusion Team June 28, 2008 06:50 PM UTC

Hi Rekha,

Thanks for your interest in Syncfusion products.

There is no direct way to achieve you requirement. But you can do this by a workaround. Please refer the following steps to be done:

1. We have to loop through the Grid data and access the value of each cell.
2. We have to compare the Rice and Wheat values based on the Comapny
3. Based on the comparision just save the Rice values which are going to be highlighted, in a collection.
4. In QueryStyleCellInfo event just check for the values in the collection and set the BackColor for the particular cell.

Please refer the below code snippet which illustrates this:

protected void GridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
if ( e.TableCellIdentity.TableCellType == Syncfusion.Web.UI.WebControls.Grid.Grouping.GridTableCellType.AlternateRecordFieldCell || e.TableCellIdentity.TableCellType == Syncfusion.Web.UI.WebControls.Grid.Grouping.GridTableCellTypeRecordFieldCell )
{
if (e.TableCellIdentity.Column.Name == "Price on Jun 1")
{
foreach (Rice obj1 in ric1)
{
if (e.Style.Text == obj1.rice1.ToString())
{
e.Style.BackColor = Color.Red;
}
}
}

if (e.TableCellIdentity.Column.Name == "Price on Jun 2")
{
foreach (Rice_nxtmnth obj1 in ric2)
{
if (e.Style.Text == obj1.rice1.ToString())
{
e.Style.BackColor = Color.Red;
}
}
}
}

}

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

http://websamples.syncfusion.com/samples/Grid.Web/5.1.0.51/Grid_ASP_Bkcolor/main.htm

Please let me know if you have any other concerns.

Regards,
Raji




AD Administrator Syncfusion Team May 12, 2009 11:50 AM UTC

How to set the border of the cell dynamically.


RP Rekha P Syncfusion Team May 14, 2009 07:07 AM UTC

Hi Girish,

Thank you for your interest in Syncfusion Products.

Border styles can be set through the Borders property, from the QueryCellStyleInfo event. Please refer the below code snipet which illustrates this.

void GridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
if (e.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell || e.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell)
{
e.Style.Borders.All = new GridBorder(GridBorderStyle.Dashed, Color.Red);
e.Handled = true;
}
}

Please refer the sample from the below link which illustrates this.

http://files.syncfusion.com/support/GGC.Web/7.2.0.20/F74099/main.htm

Please let me know if this helps you.

Thanks,
Rekha


CJ Chia Jye Kueh November 26, 2009 02:55 AM UTC

Hi,

The sample below seems to only work if we don't use the AutoFormat on the grid

http://websamples.syncfusion.com/samples/Grid.Web/5.1.0.51/Grid_ASP_Bkcolor/main.htm

How can I perform the same formatting if my grid is using one of the AutoFormat? (Please refer to the sample attached)

Thanks,
Julian



Bkcolor_with_auto_format_20ecf89a.zip


LN Lakshmi Narasimman G Syncfusion Team November 27, 2009 10:31 AM UTC

Hi Chia,

Thanks for your interest in Syncfusion products

We suggest you to handle the GridTableCellStyleInfoEventArgs Property to true in Querycellstyleinfo event

using the below code snippet
when you use AutoFormat style property

Code Snippet:
e.Handled =true;

I have created a sample to illustrate this please check the sample from below link

http://files.syncfusion.com/support/GGC.Web/6.4.0.15/74099/main.htm

We recommend you to download our latest version from the below link which has many features

http://www.syncfusion.com/downloads/latest-version

Please check the features of our latest version from the below link

http://www.syncfusion.com/products/aspnet/whatsnew

Unlock key:
If your Essential Studio license is valid, you will be able to obtain the key to install this version from
your Direct-Trac account or contact your Syncfusion Sales Representative or e-mail :
salessupport@syncfusion.com for further assistance.

Please let us know if you have any concerns.

Regards,
Lakshmi Narasimman G.


Loader.
Live Chat Icon For mobile
Up arrow icon