Back to Devexpress

GridView.FormatRuleDataUpdateCustomTrigger Event

windowsforms-devexpress-dot-xtragrid-dot-views-dot-grid-dot-gridview-a5c1f9be.md

latest5.3 KB
Original Source

GridView.FormatRuleDataUpdateCustomTrigger Event

Allows you to implement a custom algorithm to activate a FormatConditionRuleDataUpdate format.

Namespace : DevExpress.XtraGrid.Views.Grid

Assembly : DevExpress.XtraGrid.v25.2.dll

NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("Events")]
public event EventHandler<FormatRuleGridDataUpdateTriggerEventArgs> FormatRuleDataUpdateCustomTrigger
vb
<DXCategory("Events")>
Public Event FormatRuleDataUpdateCustomTrigger As EventHandler(Of FormatRuleGridDataUpdateTriggerEventArgs)

Event Data

The FormatRuleDataUpdateCustomTrigger event's data class is DevExpress.XtraGrid.Views.Grid.FormatRuleGridDataUpdateTriggerEventArgs.

Remarks

The FormatConditionRuleDataUpdate format allows you to temporarily highlight cells (with icons and/or customized appearance settings). Its FormatConditionRuleDataUpdate.Trigger property specifies when to activate this format (when a cell value changes, increases, decreases; you can also implement custom logic).

To implement custom logic to activate the format, set the Trigger property to Custom and then handle the FormatRuleDataUpdateCustomTrigger event. This event fires for a cell when its value changes.

The FormatRuleDataUpdateCustomTrigger event provides the following parameters:

  • OldValue and NewValue - Read these properties to identify the cell’s old and new values.
  • Trigger (Boolean) - Use this property to specify whether to activate the format rule.
  • Rule - Allows you to identify the currently processed format rule.

You typically need to analize the old and new cell values, and set the Trigger property to true when the values meet a custom condition.

Example

The following example creates a FormatConditionRuleDataUpdate format that temporarily highlights a Data Grid cell in the Price column when a cell value is increased by 5%.

csharp
DevExpress.XtraGrid.GridFormatRule gridFormatRule = new DevExpress.XtraGrid.GridFormatRule();
DevExpress.XtraEditors.FormatConditionRuleDataUpdate formatConditionRuleDataUpdate = new DevExpress.XtraEditors.FormatConditionRuleDataUpdate();
gridFormatRule.Column = gridView1.Columns["Price"];
gridFormatRule.Name = "priceUp";
formatConditionRuleDataUpdate.HighlightTime = 800;
formatConditionRuleDataUpdate.PredefinedName = "Green Fill, Green Text";
formatConditionRuleDataUpdate.Trigger = DevExpress.XtraEditors.FormatConditionDataUpdateTrigger.Custom;
gridFormatRule.Rule = formatConditionRuleDataUpdate;
gridView1.FormatRules.Add(gridFormatRule);

gridView1.FormatRuleDataUpdateCustomTrigger += gridView1_FormatRuleDataUpdateCustomTrigger;
//...

private void gridView1_FormatRuleDataUpdateCustomTrigger(object sender, Views.Grid.FormatRuleGridDataUpdateTriggerEventArgs e) {
    if (e.Rule.Name != "priceUp") return;
    double oldVal = Convert.ToDouble(e.OldValue);
    double newVal = Convert.ToDouble(e.NewValue);
    double diff = (newVal - oldVal) / oldVal;
    e.Trigger = diff > 0.05;
}
vb
Dim gridFormatRule As New DevExpress.XtraGrid.GridFormatRule()
Dim formatConditionRuleDataUpdate As New DevExpress.XtraEditors.FormatConditionRuleDataUpdate()
gridFormatRule.Column = GridView1.Columns("Price")
gridFormatRule.Name = "priceUp"
formatConditionRuleDataUpdate.HighlightTime = 800
formatConditionRuleDataUpdate.PredefinedName = "Green Fill, Green Text"
formatConditionRuleDataUpdate.Trigger = DevExpress.XtraEditors.FormatConditionDataUpdateTrigger.Custom
gridFormatRule.Rule = formatConditionRuleDataUpdate
GridView1.FormatRules.Add(gridFormatRule)

AddHandler GridView1.FormatRuleDataUpdateCustomTrigger, AddressOf GridView1_FormatRuleDataUpdateCustomTrigger
'...

Private Sub GridView1_FormatRuleDataUpdateCustomTrigger(sender As Object, e As DevExpress.XtraGrid.Views.Grid.FormatRuleGridDataUpdateTriggerEventArgs)
    If e.Rule.Name <> "priceUp" Then Return
    Dim oldVal As Double = Convert.ToDouble(e.OldValue)
    Dim newVal As Double = Convert.ToDouble(e.NewValue)
    Dim diff As Double = (newVal - oldVal) / oldVal
    e.Trigger = diff > 0.05
End Sub

See Also

GridView Class

GridView Members

DevExpress.XtraGrid.Views.Grid Namespace