Skip to main content

DocVariableValue Class

A class which allows you to specify the current value of a DOCVARIABLE field in the Document.CalculateDocumentVariable event handler.

Namespace: DevExpress.XtraRichEdit

Assembly: DevExpress.RichEdit.v24.2.Core.dll

NuGet Package: DevExpress.RichEdit.Core

Declaration

public class DocVariableValue

Remarks

When the Document.CalculateDocumentVariable event occurs, the current value of the DOCVARIABLE field is lost by default. You should explicitly specify the field value using the CalculateDocumentVariableEventArgs.Value property within the Document.CalculateDocumentVariable event handler.

To retain the current value of the field, set the DocVariableValue’s DocVariableValue.Current value to the CalculateDocumentVariableEventArgs.Value property.

Example

This code snippet demonstrates how to handle the RichEditControl.CalculateDocumentVariable event to insert dynamic content into the document. In this example, it is used to get weather conditions. A variable name specified in the DOCVARIABLE field indicates a choice between location and weather, while the location itself is specified by the field argument.

XtraRichEdit_CalculateDocumentVariable_Example

View Example

void eventHandler_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e) {
    if (e.Arguments.Count > 0) {
        string location = e.Arguments[0].Value.ToString();
        if ((location.Trim() == String.Empty) || (location.Contains("<"))) {
            e.Value = " ";
            e.Handled = true;
            return;
        }
        switch (e.VariableName) {
            case "Weather":
                Conditions conditions = new Conditions();
                conditions = Weather.GetCurrentConditions(location);
                e.Value = String.Format("Weather for {0}: \nConditions: {1}\nTemperature (C) :{2}\nHumidity: {3}\nWind: {4}\n",
                    location, conditions.Condition, conditions.TempC, conditions.Humidity, conditions.Wind);
                break;
            case "LOCATION":
                if (location == "DO NOT CHANGE!") e.Value = DocVariableValue.Current;
                break;
            default:
                e.Value = "LOCKED FIELD UPDATED";
                break;
        }
    }
    else {
        e.Value = "LOCKED FIELD UPDATED";
    }
    e.Handled = true;
}

Inheritance

Object
DocVariableValue
See Also