Click or drag to resize

Triggers

[This is preliminary documentation and is subject to change.]

This topic contains the following sections:

Trigger

Triggers are used to perform custom actions when a cell-value should be updated. Triggers are executed on valid rows only; so setting a cell-value on a row which is not yet added to its table, the trigger will be ignored. On computed columns the trigger will be invoked when trying to set the cell-value - not when the computed value is applied. Triggers are also ignored when value to set (after formatting) equals cells value.

By default triggers are "InstedOf". To make trigger "After" execute the "update"-parameter last inside the trigger code.

You can define a trigger in BCF-Editor/Columns/Trigger or in code:Trigger.

Define a trigger in BCF-Editor

To redirect setting value of a computed column enter in Column/Trigger: (cell, value, updateCurrent) => cell.OwningRow.SetValueObject("OtherColumnName", value). At most triggers are more complex - and having multiple lines of code in a BCF-Editor cell sucks. It is recommended to define triggers in the DataSetSetup Project (see: DataSetSetup Project File) e.g.

Trigger Definition in code
public static class Triggers {

    public static BcfTrigger<T> CreateRedirectTrigger<T>(string redirectToColumn) 
    {
        return new BcfTrigger<T>(
            (cell, value, updateCurrent) => 
            {
                cell.OwningRow.SetValue((BcfColumn<T>) cell.OwningRow.Table.Columns[redirectToColumn], value);
                // omit update on computed column 
                if(!cell.Column.HasFunction) updateCurrent();
            });
    }

    public static BcfTrigger<T> CreateRedirectToNullableTrigger<T>(string redirectToColumn) where T : struct {
        return new BcfTrigger<T>(
            (cell, value, updateCurrent) => 
            {
                cell.OwningRow.SetValue((BcfColumn<T?>)cell.OwningRow.Table.Columns[redirectToColumn], value);
                // omit update on computed column 
                if(!cell.Column.HasFunction) updateCurrent();
            });
    }
}
and enter in Column/Trigger: Triggers.CreateRedirectTrigger("OtherColumnName").

Define trigger in code
((BcfColumnSetup<string>) myDataSetSetup.Tables[0].Columns[0]).Trigger = (cell, value, update) => 
  { 
    Console.Write("Begin cell update..."); 
    update(); 
    Console.WriteLine(" done."); 
  };
See Also