Articles in this section

How to Apply Conditional Formats Cell in WinForms GridGroupingControl?

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#

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

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 

The screenshot below illustrates the conditional formatting in GridGroupingControl.

Applied conditional formats to the cell

Samples:

C#: Conditional_Formatting_CS

VB: Conditional_Formatting_VB

 

Reference Link: Conditional Formatting

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