How to: Create Check Box
The following example demonstrates how to create a check box in the Snap document.
- Call the IRichEditDocumentServer.LoadDocumentTemplate method to load the document template to the server.
- Enable the document modification by calling the SubDocument.BeginUpdate method.
- Create new SnapCheckBox instance by calling the ISnapFieldOwner.CreateSnCheckBox method. Pass the position to place the check box and the data field to which it corresponds to the method.
- Convert the check box field to a Snap field. To do that, call the ISnapFieldOwner.ParseField method. Note that if this step is skipped, you won’t be able to modify the check box.
- Start the checkbox modification by calling the SnapEntity.BeginUpdate method.
- Specify the check state by setting the SnapCheckBox.State property.
- To finalize the modification, call SnapEntity.EndUpdate method.
- Call the FieldCollection.Update method to update the check box field.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/snap-document-server-api-t429162
server.LoadDocumentTemplate("Template.snx");
server.Document.BeginUpdate();
SnapCheckBox checkbox = server.Document.CreateSnCheckBox(server.Document.Range.Start, "Discontinued");
server.Document.ParseField(checkbox.Field);
checkbox.BeginUpdate();
checkbox.State = System.Windows.Forms.CheckState.Checked;
checkbox.EndUpdate();
checkbox.Field.Update();