GridView.FormatRuleDataUpdateCustomTrigger Event
Allows you to implement a custom algorithm to activate a FormatConditionRuleDataUpdate format.
Namespace: DevExpress.XtraGrid.Views.Grid
Assembly: DevExpress.XtraGrid.v24.1.dll
NuGet Packages: DevExpress.Win.Grid, DevExpress.Win.Navigation
Declaration
[DXCategory("Events")]
public event EventHandler<FormatRuleGridDataUpdateTriggerEventArgs> FormatRuleDataUpdateCustomTrigger
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%.
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;
}