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.v18.2.Core.dll
Declaration
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.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-use-document-variable-docvariable-fields-e3099
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;
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the DocVariableValue class.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.