Articles in this section

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

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.


//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";
      }
   }
}
' Triggers event.
AddHandler Me.gridGroupingControl1.QueryCellStyleInfo, AddressOf Me.gridGroupingControl1_QueryCellStyleInfo

Private Sub gridGroupingControl1_QueryCellStyleInfo(sender As Object, e As Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs)
    If e.TableCellIdentity.TableCellType = GridTableCellType.RecordFieldCell OrElse
       e.TableCellIdentity.TableCellType = GridTableCellType.AlternateRecordFieldCell Then

        ' Checks for the column name when the cell value is greater than 5.
        If e.TableCellIdentity.Column.MappingName = "Col1" AndAlso Convert.ToInt32(e.Style.CellValue) > 5 Then
            e.Style.BackColor = Color.LightBlue
            e.Style.Format = "##.00"
        End If
    End If

The screenshot below displays the conditional format for a single cell in GGC.

 

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)
Access denied
Access denied