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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to conditionally set the format of a single cell in the WinForms GridGroupingControl?

Platform: WinForms |
Control: GridGroupingControl |
Published Date: April 30, 2011 |
Last Revised Date: February 13, 2020

Conditional formatting

The formatting of a cell can be handled in the QueryCellStyleInfo event. The e.TableCellIdentity.MappingName and e.Style.CellValue properties can be used to check the particular column cell values.

C#

//Triggers event.
this.gridGroupingControl1.QueryCellStyleInfo += new Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventHandler(this.gridGroupingControl1_QueryCellStyleInfo);
private void gridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e)
{
   If(e.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell || e.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell)
   {
      // Checks for the column name when the cellvalue is greater than 5.
      if(e.TableCellIdentity.Column.MappingName == "Col1"  && (int)e.Style.CellValue>5)
      {
        e.Style.BackColor=Color.LightBlue;
        e.Style.Format="##.00";
      }
   }
}

VB

'Triggers event. 
Private Me.gridGroupingControl1.QueryCellStyleInfo += New Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventHandler(AddressOf Me.gridGroupingControl1_QueryCellStyleInfo)
Private Sub gridGroupingControl1_QueryCellStyleInfo(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs)
   If(e.TableCellIdentity.TableCellType = GridTableCellType.RecordFieldCell OrElse e.TableCellIdentity.TableCellType = GridTableCellType.AlternateRecordFieldCell)
     'Checks for the column name when the cellvalue is greater than 5.
     If e.TableCellIdentity.Column.MappingName = "Col1" AndAlso CInt(Fix(e.Style.CellValue))>5 Then
        e.Style.BackColor=Color.LightBlue
        e.Style.Format="##.00"
     End If
End Sub

 

Conditional format applied to each cell in  first column

Figure 1: Conditional format applied to each cell in column “Col1”

Samples:

C#: ConditionalFormatCell-C#

VB: ConditionalFormatCell-VB

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon 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.Close Icon

Live Chat Icon For mobile
Live Chat Icon