Hi,
At the moment I have a report setup dynamically by code, I have a variable called "StockCode".
I wish to know how I can link a custom form to a StiReport (user designer), so that when the user wish to "preview" the report, a custom form will popup allowing them to choose values for the variable "StockCode", so that the report will run correctly.
I need to add the form and link it to the preview event through code.
Any help will be great
thanks
Adding a custom form to a stiReport during preview event
Adding a custom form to a stiReport during preview event
You can add a custom Form to the report through code in the following way:
One note. You can add an event handlers to the report after the report compiling.
Thank you.
Code: Select all
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Stimulsoft.Report;
using Stimulsoft.Report.Components;
using Stimulsoft.Report.ReportControls;
using Stimulsoft.Base.Drawing;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public StiReport report;
public void ButtonControl1_Click(object sender, System.EventArgs e)
{
MessageBox.Show(TextBoxControl1.Text);
//report["StockCode"] = (report["TextBoxControl1"] as StiTextBoxControl).Text;
}
private void Form1_Load(object sender, EventArgs e)
{
report = new StiReport();
StiForm MyForm = new StiForm();
MyForm.Name = "MyForm";
MyForm.Size = new System.Drawing.Size(304, 232);
MyForm.Text = "MyFormText";
MyForm.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F);
MyForm.Page = MyForm;
MyForm.Report = report;
// ButtonControl1
StiButtonControl ButtonControl1 = new StiButtonControl();
ButtonControl1.ClientRectangle = new RectangleD(88, 136, 96, 24);
ButtonControl1.DialogResult = System.Windows.Forms.DialogResult.OK;
ButtonControl1.Location = new System.Drawing.Point(88, 136);
ButtonControl1.Name = "ButtonControl1";
ButtonControl1.Size = new System.Drawing.Size(96, 24);
ButtonControl1.Text = "My Button";
ButtonControl1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F);
ButtonControl1.Page = MyForm;
ButtonControl1.Parent = MyForm;
// TextBoxControl1
StiTextBoxControl TextBoxControl1 = new StiTextBoxControl();
TextBoxControl1.ClientRectangle = new Stimulsoft.Base.Drawing.RectangleD(88, 64, 96, 20);
TextBoxControl1.Location = new System.Drawing.Point(88, 64);
TextBoxControl1.Name = "TextBoxControl1";
TextBoxControl1.Size = new System.Drawing.Size(96, 20);
TextBoxControl1.Text = "MyTextBox";
TextBoxControl1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F);
TextBoxControl1.Page = MyForm;
TextBoxControl1.Parent = MyForm;
// Add to MyForm.Components
MyForm.Components.AddRange(new StiComponent[] {ButtonControl1,TextBoxControl1});
// Button Control Click Event
//ButtonControl1.
//ButtonControl1.Click += new System.EventHandler(ButtonControl1_Click);
report.Pages.Add(MyForm);
report.Compile();
(report["ButtonControl1"] as StiButtonControl).Click += new System.EventHandler(ButtonControl1_Click);
report.Show();
}
}
}
Thank you.
Adding a custom form to a stiReport during preview event
Thanks very much for your reply, it was really helpful ! Although I was wanting to add the stiForm to the "Designer" rather than the preview control and I was wanting to capture the "Preview control TAB" load event in the designer, not the stand alone preview control. Nevertheless, the code gave me some great ideas
Adding a custom form to a stiReport during preview event
Please use the static event of the StiDesigner class PreviewingReportjing wrote:Thanks very much for your reply, it was really helpful ! Although I was wanting to add the stiForm to the "Designer" rather than the preview control and I was wanting to capture the "Preview control TAB" load event in the designer, not the stand alone preview control. Nevertheless, the code gave me some great ideas
Thank you.
Adding a custom form to a stiReport during preview event
Hi jing,jing wrote:Thanks very much for your reply, it was really helpful ! Although I was wanting to add the stiForm to the "Designer" rather than the preview control and I was wanting to capture the "Preview control TAB" load event in the designer, not the stand alone preview control. Nevertheless, the code gave me some great ideas
To add a Blank Form to the designer the following should work:
Code: Select all
Stimulsoft.Report.StiReport report = new Stimulsoft.Report.StiReport();
Stimulsoft.Report.ReportControls.StiForm myForm = new Stimulsoft.Report.ReportControls.StiForm(report);
myForm.Name = "Form1";
report.Pages.Add(myForm);
report.Design();
Whatever controls you need to add dynamically to the Form itself afterwards can be done following Edward's helpful instructions.