Hello –
What I’d like to create is a variation on a merge field, much like the two special keywords IMAGE:
and TABLESTART:
, only I’d like to create one called CHECKBOX:
.
In other words, I’d like my end users to be able to create a merge field that might look like this:
{ MERGEFIELD CHECKBOX:IsCitizen }
After performing the merge, what I’m hoping to achieve is to have Words insert a Checkbox Form Field at the location of the merge field, very much like the functionality of the IMAGE: tag, using DocumentBuilder.
However, I can’t just use the other examples in this forum that use a merge event handler to evaluate the data, looking for a boolean field, and using the builder to insert a checkbox because I need something that is generic enough for my end users to be able to choose to use, or not, as they wish.
The trouble I’m running into is that even in an event handler, if the merge field is named as I suggested above (including the word “Checkbox:”) the e.FieldValue won’t be the corresponding value from my data table.
Here’s what I started to write, but abandoned:
if (e.DocumentFieldName.StartsWith("Checkbox:", StringComparison.OrdinalIgnoreCase))
{
DocumentBuilder builder = new DocumentBuilder(e.Document);
builder.MoveToMergeField(e.DocumentFieldName);
// e.FieldValue won’t have a value though…
if (!String.IsNullOrEmpty(e.FieldValue.ToString()))
builder.InsertCheckBox(e.FieldName, true, 0);
else
builder.InsertCheckBox(e.FieldName, false, 0);
}
Do you have other suggestions on how I might accomplish this?