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();
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…