Search code examples
vb.netwinformscrystal-reports

pass checkbox value to crystal report parameter


I am creating a form in winforms that passes all values on the form as parameters to a crystal report. What I am looking to accomplish is when a checkbox is checked on my form i want it to display as a checked box on my crystal report.

I know how to accomplish this by saving the value to the database, and then pulling that value from the database and applying to the report, but I'd really like all of the fields on the report to be parameter fields that get populated from the form. Is there a method to send the checkbox value from the form straight to the report without saving the value in the database?

for example i am passing text fields from the form to the report using this VB code:

Dim NewRpt As RptPrintCustomer = New RptPrintCustomer()
NewRpt.SetParameterValue("Customer", CustomerName.Text)

Dim fresh As FrmPrintCustomer = New FrmPrintCustomer()
fresh.LinkReport(NewRpt)
fresh.Show()

I would like to accomplish the same feat for a checkbox.

Thanks in advance for any insight.


Solution

  • My solution to this, without having to create a datatable, and go that whole route, was the following.

    I created a square box on the crystal report. I created a parameter field (using the name "ParameterName" for this example) and placed that parameter field with it's first letter being centered inside of the aforementioned box. Then I simply used the following VB code.

    Dim NewRpt as RptPrintCustomer = New RptPrintCustomer
    
    If Checkbox.checked = True Then
        NewRpt.SetParameterValue("ParameterName", "x")
    Else
        NewRpt.SetParameterValue("ParameterName", "")
    End If
    

    This gives me a box with an "x" in it if the checkbox is checked on the form, and an empty box if the checkbox is not checked on the form.

    This is much more efficient than creating a datatable for one lonely boolean field. And effort is minimal.