Articles in this section
Category / Section

How to apply the conditional formats to the cell using GridConditionalFormatDescriptor in WinForms GridGroupingControl?

1 min read

Conditional formatting

By default, the conditional format will be set to the entire row. In order to set the ConditionalFormatting for a particular cell at run time, GridConditionalFormatDescriptor and QueryCellInfo event can be used. In QueryCellInfo event, the CompareRecord() method can be used to compare the records with condition.

C#

//Form() 
GridConditionalFormatDescriptor descriptor = new GridConditionalFormatDescriptor();
 
//To add the condition
descriptor.Expression = "[CategoryID]>50";
gridGroupingControl1.TableDescriptor.ConditionalFormats.Add(descriptor);
 
//Event Triggering
this.gridGroupingControl1.QueryCellStyleInfo += GridGroupingControl1_QueryCellStyleInfo;
 
//Event Customization
private void GridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
    if (e.TableCellIdentity.Column != null && e.TableCellIdentity.Column.Name == "Description" && e.TableCellIdentity.DisplayElement.Kind == DisplayElementKind.Record)
    {
        Record record = e.TableCellIdentity.DisplayElement.GetRecord();
        if (descriptor.CompareRecord(record))
        {
            e.Style.BackColor = Color.Yellow;
        }
    }
}

 

VB

‘Form() 
Private descriptor As New GridConditionalFormatDescriptor()
 
'To add the condition
 descriptor.Expression = "[CategoryID]>50"
gridGroupingControl1.TableDescriptor.ConditionalFormats.Add(descriptor)
 
'Event Triggering
AddHandler Me.gridGroupingControl1.QueryCellStyleInfo, AddressOf GridGroupingControl1_QueryCellStyleInfo
 
'Event Customization
Private Sub GridGroupingControl1_QueryCellStyleInfo(ByVal sender As Object, ByVal e As GridTableCellStyleInfoEventArgs)
    If e.TableCellIdentity.Column IsNot Nothing AndAlso e.TableCellIdentity.Column.Name = "Description" AndAlso e.TableCellIdentity.DisplayElement.Kind = DisplayElementKind.Record Then
        Dim record As Record = e.TableCellIdentity.DisplayElement.GetRecord()
        If descriptor.CompareRecord(record) Then
            e.Style.BackColor = Color.Yellow
        End If
    End If
End Sub

 

Screenshot

Applied conditional formats to the cell

Samples:

C#: Conditional_Formatting_CS

VB: Conditional_Formatting_VB

Reference link: https://help.syncfusion.com/windowsforms/classic/gridgroupingcontrol/conditional-formatting

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