How should I change the TextFormat of Text as Date format

Stimulsoft Reports.NET discussion
Post Reply
satisht
Posts: 150
Joined: Mon Apr 09, 2007 12:28 am
Location: Pune

How should I change the TextFormat of Text as Date format

Post by satisht »

I need to change the TextFormat of text as a Date format at runtime, how should I do this ? Give me code
Brendan
Posts: 309
Joined: Sun Jul 16, 2006 12:42 pm
Location: Ireland

How should I change the TextFormat of Text as Date format

Post 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();
satisht
Posts: 150
Joined: Mon Apr 09, 2007 12:28 am
Location: Pune

How should I change the TextFormat of Text as Date format

Post by satisht »

Thank You
Vital
Posts: 1278
Joined: Fri Jun 09, 2006 4:04 am

How should I change the TextFormat of Text as Date format

Post 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)
  }
}
Post Reply