Page 1 of 1

How should I change the TextFormat of Text as Date format

Posted: Wed Aug 01, 2007 9:27 am
by satisht
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

Posted: Wed Aug 01, 2007 12:45 pm
by Brendan
This is some sample code I had.
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

Posted: Wed Aug 01, 2007 11:20 pm
by satisht
Thank You

How should I change the TextFormat of Text as Date format

Posted: Fri Aug 03, 2007 1:49 pm
by Vital
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)
  }
}