Dynamic TableCell format

Hello,


Is there any way I can format the text of a table cell dynamically?


Let's say I have this class in my Users data source:

public class Person

{

public string Name { get; set;}

public DateTime Date { get; set;}

public string UserDateFormat { get; set;}

}


Is there any way to do something like this?


public void OnBeforeTableCellPrint(object sender, EventArgs e)

{

var person = ??? //get the person object somehow?

var cell = ??? //get the cell somehow?

cell.Text = person.Date.ToString(person.UserDateFormat);

}

Comments

  • Hello!

    Inside the BeforePrint event handler for a table or cell, the values for the current record are retrieved using `Report.GetColumnValue(...)`, and the cell itself is retrieved by casting `(TableCell)sender`:

    private void Cell1_BeforePrint(object sender, EventArgs e)
    {
    var cell = (TableCell)sender;
    var dt = (DateTime)Report.GetColumnValue(“Users.Date”);
    var fmt = Convert.ToString(Report.GetColumnValue(“Users.UserDateFormat”));
    cell.Text = dt.ToString(fmt);
    }
    

    (It’s even simpler to do this directly in the cell text without using an event handler: [((DateTime)[Users.Date]).ToString([Users.UserDateFormat])])

This discussion has been closed.