Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a form that contains 3 comboboxes and a button like shown below

enter image description here

and a report that containes 3 parameters that are bounded to richtext

enter image description here

i used the following code for this process when clicking the button Print but parameters aren't passed and richtext fields are empty

private void btnPrint_Click(object sender, EventArgs e)
{
    // Create a report instance.
    var report = new XtraReport1();

    // Obtain a parameter, and set its value.
    report.ClassName.Value    = cmbClass.SelectedText;
    report.SubclassName.Value = cmbDivision.SelectedText;
    report.StudentName.Value  = cmbStudent.SelectedText;

    report.RequestParameters = false;    // Hide the Parameters UI from end-users.
    report.ShowPreview();
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
435 views
Welcome To Ask or Share your Answers For Others

1 Answer

Use XtraReport.Parameters collection to pass combobox values into parameter names as shown in below example:

private void btnPrint_Click(object sender, EventArgs e)
{
    // Create a report instance.
    var report = new XtraReport1();

    // Obtain a parameter, and set its value.
    report.Parameters["ClassName"].Value = cmbClass.SelectedText;
    report.Parameters["SubclassName"].Value = cmbDivision.SelectedText;
    report.Parameters["StudentName"].Value = cmbStudent.SelectedText;

    report.RequestParameters = false; // Hide the Parameters UI from end-users.
    report.ShowPreview();
}

Or you may declare an overload constructor which assigns parameter values inside it, then create XtraReport instance using overloaded constructor arguments:

// XtraReport
public partial class ReportName : DevExpress.XtraReports.UI.XtraReport
{
    // default parameterless constructor here

    public ReportName(string ClassName, string SubclassName, string StudentName)
    {
        InitializeComponent();

        this.Parameters["ClassName"].Value = ClassName;
        this.Parameters["SubclassName"].Value = SubclassName;
        this.Parameters["StudentName"].Value = StudentName;
    }
}

// Form code
private void btnPrint_Click(object sender, EventArgs e)
{
    // Create a report instance.
    var report = new XtraReport1(cmbClass.SelectedText, cmbDivision.SelectedText, cmbStudent.SelectedText);

    report.RequestParameters = false; // Hide the Parameters UI from end-users.
    report.ShowPreview();
}

Reference: Passing Parameter Values at Runtime

Update:

If SelectedText property for each textbox always have null value, you can use Text or SelectedItem property to get actual combo box value (similar issue here).

private void btnPrint_Click(object sender, EventArgs e)
{
    // Create a report instance.
    var report = new XtraReport1();

    // Obtain a parameter, and set its value.
    report.Parameters["ClassName"].Value = cmbClass.Text;
    report.Parameters["SubclassName"].Value = cmbDivision.Text;
    report.Parameters["StudentName"].Value = cmbStudent.Text;

    report.RequestParameters = false; // Hide the Parameters UI from end-users.
    report.ShowPreview();
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...