How should I change the TextFormat of Text as Date format
How should I change the TextFormat of Text as Date format
I need to change the TextFormat of text as a Date format at runtime, how should I do this ? Give me code
How should I change the TextFormat of Text as Date format
This is some sample code I had.
You can replace the Variable lines with a column from your Datasource
You can replace the Variable lines with a column from your Datasource
Code: Select all
Stimulsoft.Report.StiReport report = new Stimulsoft.Report.StiReport();
//Create Text Component to Display my Value
Stimulsoft.Report.Components.StiText myTextComp = new Stimulsoft.Report.Components.StiText(new Stimulsoft.Base.Drawing.RectangleD(5, 5, 5, 2));
//Use a Variable to Demonstrate Formatting
report.Dictionary.Variables.Add("MyDate", typeof(DateTime));
report.Dictionary.Variables["MyDate"].ValueObject = DateTime.Now;
//Use My Variable in the Text Component
myTextComp.Text = new Stimulsoft.Report.Components.StiExpression("{MyDate}");
//Set the Formatting for the Text Component
myTextComp.TextFormat = new Stimulsoft.Report.Components.TextFormats.StiDateFormatService("dd MMM yyyy", String.Empty);
//myTextComp.TextFormat = new Stimulsoft.Report.Components.TextFormats.StiDateFormatService("d", String.Empty);
//Add Text Component to my Page and Compile/Render
report.Pages[0].Components.Add(myTextComp);
report.Compile();
report.Show();
How should I change the TextFormat of Text as Date format
You can receive all components with help of this code:
Code: Select all
StiComponentsCollection comps = report.GetComponents();
foreach (StiComponent comp in comps)
{
StiText text = comp as StiText;
if (text != null)
{
//At this place you can use code which provide for you Brendan (Thanks)
}
}