Articles in this section
Category / Section

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

1 min read

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

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied