windowsforms-devexpress-dot-xtragrid-dot-views-dot-grid-dot-gridview-a5c1f9be.md
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
[DXCategory("Events")]
public event EventHandler<FormatRuleGridDataUpdateTriggerEventArgs> FormatRuleDataUpdateCustomTrigger
<DXCategory("Events")>
Public Event FormatRuleDataUpdateCustomTrigger As EventHandler(Of FormatRuleGridDataUpdateTriggerEventArgs)
The FormatRuleDataUpdateCustomTrigger event's data class is DevExpress.XtraGrid.Views.Grid.FormatRuleGridDataUpdateTriggerEventArgs.
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:
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.
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%.
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;
}
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