Skip to main content
A newer version of this page is available. .

How to: Create a Snap Template (Runtime Sample)

  • 2 minutes to read

This topic describes the steps used to calculate a summary function in your report.

This procedure generates the Snap template in code by executing the following steps.

  1. Create a SnapList and start its modification by calling the SnapEntity.BeginUpdate method.
  2. Create a SnapList.ListHeader header, add a Table to the header and insert column names.
  3. Modify the row template. The row template has the SnapDocument interface accessible using the SnapList.RowTemplate property.
  4. Add a table to the template and insert data-bound text fields into its cells using the ISnapFieldOwner.CreateSnText method.
  5. Format the table in the list.
  6. Apply filter to data in the list.
  7. Sort data in the list.
  8. Group data in the list
  9. Finalize the modification by calling the SnapEntity.EndUpdate method.
  10. Update the result by calling the Field.Update method.
private void GenerateLayout(SnapDocument doc) {
    // Add a Snap list to the document.
    SnapList list = doc.CreateSnList(doc.Range.End, @"List");
    list.BeginUpdate();
    list.EditorRowLimit = 100;

    // Add a header to the Snap list.                                                                   
    SnapDocument listHeader = list.ListHeader;
    Table listHeaderTable = listHeader.Tables.Create(listHeader.Range.End, 1, 3);
    TableCellCollection listHeaderCells = listHeaderTable.FirstRow.Cells;
    listHeader.InsertText(listHeaderCells[0].ContentRange.End, "Product Name");
    listHeader.InsertText(listHeaderCells[1].ContentRange.End, "Units in Stock");
    listHeader.InsertText(listHeaderCells[2].ContentRange.End, "Unit Price");

    // Customize the row template.
    SnapDocument listRow = list.RowTemplate;
    Table listRowTable = listRow.Tables.Create(listRow.Range.End, 1, 3);
    TableCellCollection listRowCells = listRowTable.FirstRow.Cells;
    listRow.CreateSnText(listRowCells[0].ContentRange.End, @"ProductName");
    listRow.CreateSnText(listRowCells[1].ContentRange.End, @"UnitsInStock");
    listRow.CreateSnText(listRowCells[2].ContentRange.End, @"UnitPrice \$ $0.00");

    // Apply formatting, filtering and sorting to the Snap list. 
    FormatList(list);
    FilterList(list);
    SortList(list);
    GroupList(list);

    list.EndUpdate();
    list.Field.Update();
}