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

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.AppendParagraph();
            }

            //Insert a new paragraph:
            template.AppendParagraph();

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