All docs
V20.1
20.1
19.2
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

How to: Convert a SnapList's Row Template to Paragraphs (Runtime Sample)

  • 3 minutes to read

The code sample below shows how to convert a SnapList's row template to paragraphs. When you drag and drop fields from the Data Explorer, they are inserted into a report in the following format: Field's Display Name = Field Value.

IMAGE

  1. Create a collection of data fields and fill it in the SnapDocument.BeforeInsertSnList event handler.

  2. In the SnapDocument.PrepareSnList event handler, do the following:

  3. Reset the dataFields collection.

using System;
using System.Collections.Generic;
using System.Data;
using DevExpress.Snap.Core.API;

//...

List<DataFieldInfo> dataFields;

void Document_BeforeInsertSnList(object sender, BeforeInsertSnListEventArgs e)
{
    //Fill the data fields collection
    this.dataFields = e.DataFields;
}
void Document_PrepareSnList(object sender, PrepareSnListEventArgs e)
{
    for (int i = 0; i < e.Template.Fields.Count; i++)
    {
        //Convert each field to snap field
        SnapList list = e.Template.ParseField(field) as SnapList;

        //Check whether the returned object is not null
        if(list !=null)
        {
            //Open the snap entity for modification:
            list.BeginUpdate();

            //Clear the list header and row templates:
            list.ListHeader.Delete(list.ListHeader.Range);
            SnapDocument template = list.RowTemplate;
            template.Delete(template.Range);

            //Insert each data field as simple text:
            foreach(DataFieldInfo dataField in this.dataFields)
            {
                template.AppendText(string.Format("{0} = ", dataField.DisplayName));
                template.CreateSnText(template.Range.End, dataField.DataPaths[dataField.DataPaths.Length - 1]);
                template.Paragraphs.Append();
            }

            //Insert a new paragraph:
            template.Paragraphs.Append();

            //End the list's update:
            list.EndUpdate();
        }
    }
    this.dataFields = null;
}