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.

GridGroupingControl and row background color

Thread ID:

Created:

Updated:

Platform:

Replies:

125925 Jul 12,2007 08:04 AM Dec 8,2016 09:05 AM Windows Forms 15
loading
Tags: GridGroupingControl
Thomas J Ekman
Asked On July 12, 2007 08:04 AM

How do I set background color on a row depending on a condition?
The help documentation says that I should create a GridConditionalFormatDescriptor class, set the Expression property of it, and then the color value of the Appearance.RecordFieldCell property, and conclude by calling TableDescriptor.ConditionalFormats.Add() with the GridConditionalFormatDescriptor object as parameter.

As far as I can tell from the documentation, this only applies to Windows Forms. How should I accomplish this in ASP.NET? I use Visual Studio 2005 with SyncFusion 5.1.1.0. The ASP.NET uses version 2 of dotnet.

Gokul B [Syncfusion]
Replied On July 12, 2007 06:11 PM

Hi Thomas,

As mentioned in our help documentation, you have to use the GridConditionalFormatDescriptor class to apply the cell style. Attached is the sample which Illustrates how different formats can be applied to the grid’s cells, conditionally, based on the cell’s values.

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

* GridConditionalFormatDescriptor is used to set Styles for grid cells according to the conditions specified.
* Adding the above descriptor to the corresponding TableDescriptor will affect all the cells in that table.

Let us know if it helps.

Thanks for using Syncfusion products.

Regards,
Gokulkumar B

Yarius Yacinus
Replied On July 19, 2007 09:04 AM

Hi Gollukurman,

In you sample your compare the selected item of DDL and the value in your grid,but I would like to know how to compare directely the value of the column record (speciely I have problem with date comparaison beetween the value in the grid which is DateTime type and current date DateTime.today) and how to set backcolor only for this column not in anyrecordfieldcell.
below part of my code (sorry I couldn't make as an attachement due to busy work)
protected void set_color(){
System.Drawing.Color C = new Color();
C=Color.FromName("red");
string d=System.Convert.ToString(DateTime.Now);
Response.Write(DateTime.Parse("18/07/2007").ToString());
GridConditionalFormatDescriptor gcfd1 = new GridConditionalFormatDescriptor();
gcfd1.Name = "Criteria1";
string str=GridGroupingControl1.TableDescriptor.Columns[15].ToString();
gcfd1.Expression=System.Convert.ToString(str.CompareTo("18/07/2007"));
gcfd1.Appearance.RecordFieldCell.BackColor=C;
this.GridGroupingControl1.TableDescriptor.ConditionalFormats.Add(gcfd1);


thank you
Ragards

Yacinus

Valli [Syncfusion]
Replied On July 20, 2007 02:58 AM

Hi Yacinus,

Attached is a sample as per your requirement.

http://websamples.syncfusion.com/samples/Grid.Web/5.1.0.51/Forum-63992/main.htm

The above sample compares 2 date values. It compares the datevalue of the 'HireDate' column with the date value '5/1/1992'. If you need you can replace '5/1/1992' with current date.

Based on the result the backcolor of the cell is changed.

1. When the hiredate is equal to '5/1/1992' the backcolor of the cell is changed to Green.
2. When the hiredate is greater than '5/1/1992' the backcolor of the cell is changed to yellow.
3. When the hiredate is less than than '5/1/1992' the backcolor of the cell is changed to red.

All the described functionalities are done in the 'OnQueryCellStyleInfo' event.

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

Regards,
Valli

Ricardo Ismael Sanchez Condori
Replied On February 26, 2010 05:05 PM

hi, the link is break ! does anyone write the code in a new post!.

greetings !

Rajadurai C [Syncfusion]
Replied On February 26, 2010 09:59 PM

Hi Ismael,

Thanks for your interest in Syncfusion Products.

I apologize for the inconvenience caused with the broken link. Please make use of the following modified link for the same.
http://help.syncfusion.com/samples/Grid.Web/5.1.0.51/Forum-63992/main.htm

Regards,
Rajadurai

Falcon CK
Replied On September 11, 2016 04:46 AM

Hi, can i have the exactly same function but is windows form ?

Amal Raj Umapathy Selvam [Syncfusion]
Replied On September 12, 2016 02:23 AM

Hi Falcon, 
 
Thanks for using Syncfusion products. 
 
We have created a simple sample based on your requirement in Conditional Formatting to set the Back Color of a row based on condition. Please make use of the below sample and the code, 
 
Code Example 
//Initialize Condition Format. 
GridConditionalFormatDescriptor gcfd = new GridConditionalFormatDescriptor(); 
gcfd.Appearance.AnyRecordFieldCell.BackColor = Color.Green; 
gcfd.Appearance.AnyRecordFieldCell.TextColor = Color.White; 
var checkDate = DateTime.Now.AddDays(1).ToString("MM/dd/yyyy"); 
gcfd.Expression= "[HiredDate] < \'"+checkDate+"\'"; 
 
//To add the conditional format instances to the ConditionalFormats collection. 
this.gridGroupingControl1.TableDescriptor.ConditionalFormats.Add(gcfd); 
 
Sample Link 
 
For more information about Conditional Formatting, please refer to the below User guide documentation and our Dashboard sample, 
 
UG Link 
 
Dashboard Sample Location 
<Install_Location>\Syncfusion\EssentialStudio[Version_Number]\Windows\Grid.Grouping.Windows\Samples\Styling and Formatting\Conditional Formatting Demo 
 
Regards, 
Amal Raj U. 


Falcon CK
Replied On September 12, 2016 05:27 AM

Hi, thank you for reply, but i think you've misunderstand my question. 
I need to make a styling for a particular cell, based on another column value. 
For eg.

Row 1
Cell['gender'] => "male"
Cell['name'] => styling as blue


Row 2
Cell['gender'] => "female"
Cell['name'] => styling as pink

The styling is based on that particular row and certain column's value. Is that possible to do it in windows form and i am using grid grouping control. 

Amal Raj Umapathy Selvam [Syncfusion]
Replied On September 13, 2016 12:44 AM

Hi Falcon, 

Thanks for the update. 

The reported scenario can be achieved by using QueryCellStyleInfo event. Please make use of the below code and the sample, 
 
Code Example 
//Event Subscription. 
this.gridGroupingControl1.QueryCellStyleInfo += new GridTableCellStyleInfoEventHandler(gridGroupingControl1_QueryCellStyleInfo); 
 
void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e) 
    GridTableCellStyleInfo style = e.Style as GridTableCellStyleInfo
    if (style != null && style.TableCellIdentity != null && style.TableCellIdentity.DisplayElement != null 
        && style.TableCellIdentity.DisplayElement.GetRecord() != null && style.TableCellIdentity.Column != null
    { 
        Record record = style.TableCellIdentity.DisplayElement.GetRecord(); 
        string value = record["Gender"].ToString(); 
        if (value == "Male" && style.TableCellIdentity.Column.Name == "Name"
        { 
            style.BackColor = Color.Blue; 
            style.TextColor = Color.White; 
        } 
        else if (style.TableCellIdentity.Column.Name == "Name"
        { 
            style.BackColor = Color.Pink; 
            style.TextColor = Color.White; 
        } 
    } 
 
Sample Link 
 
Regards, 
Amal Raj U. 


Falcon CK
Replied On September 13, 2016 10:33 AM

Hi, awesome, thank you, it works !!

Amal Raj Umapathy Selvam [Syncfusion]
Replied On September 14, 2016 12:42 AM

Hi Falcon, 

Thanks for the update. 

We are glad to know that the issue has been resolved at your end, please let us know if you have any other concerns. 

Regards, 
Amal Raj U.          


Dash
Replied On December 7, 2016 09:58 PM

Hello.  I added one line to the sample project:


gridGroupingControl1.TableOptions.ListBoxSelectionMode = SelectionMode.MultiExtended;

With that option, the row selection color overrides the blue/pink color when a row and some column other than Name is selected.  Is there any way to exempt certain columns from the row selection color (in this case "Name") so the color scheme stays with the column regardless of whether the row is selected?

Thank you.



Amal Raj Umapathy Selvam [Syncfusion]
Replied On December 8, 2016 06:17 AM

Hi Vincent, 

Thanks for using Syncfusion products. 

By default, when Selection mode is enabled, the default SelectionBackColor will override the cells BackColor for selection. If you want to avoid this overriding of SelectionBackColor, then the TableControlDrawCellDisplayText event can be used. Please make use of the below code, 
 
Code Example 
//Event Subscription. 
this.gridGroupingControl1.TableControlDrawCellDisplayText += new GridTableControlDrawCellDisplayTextEventHandler(gridGroupingControl1_TableControlDrawCellDisplayText); 
 
void gridGroupingControl1_TableControlDrawCellDisplayText(object sender, GridTableControlDrawCellDisplayTextEventArgs e) 
    GridTableCellStyleInfo style = e.Inner.Style as GridTableCellStyleInfo
    if (style != null && style.TableCellIdentity != null && style.TableCellIdentity.DisplayElement != null 
        && style.TableCellIdentity.DisplayElement.GetRecord() != null && style.TableCellIdentity.Column != null
    { 
        Record record = style.TableCellIdentity.DisplayElement.GetRecord(); 
        string value = record["Gender"].ToString(); 
        if (record.IsSelected()) 
        { 
            if (value == "Male" && style.TableCellIdentity.Column.Name == "Name"
            { 
                e.Inner.Graphics.FillRectangle(new SolidBrush(Color.Blue), e.Inner.TextRectangle); 
            } 
            else if (style.TableCellIdentity.Column.Name == "Name"
            { 
                e.Inner.Graphics.FillRectangle(new SolidBrush(Color.Pink), e.Inner.TextRectangle); 
            } 
        } 
    } 
 
Sample Link 
 
 
 
Regards, 
Amal Raj U. 


Dash
Replied On December 8, 2016 07:16 AM

Thank you, Amal.  Works perfectly!

Amal Raj Umapathy Selvam [Syncfusion]
Replied On December 8, 2016 09:05 AM

Hi Vincent, 

Thanks for your update. 

We are glad to that the provided solution in our last update has resolved your query. Please let us know, if you have any other concerns. 

Regards, 
Amal Raj U. 


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.

;