Click to See Complete Forum and Search --> : use variables from winform in the CrystalReportViewer


meax80
February 28th, 2010, 02:43 AM
in my win form i have two datetimepickers.

first user selects dates from those two controls to filter the data between 2 dates.

and then click a button to generate the report.

in the same form i have CrystalReportViewer control.

when the user clicks the button i can get the data and show it in the CrystalReportViewer.

what i can't do is add a title to report header using those 2 dates selected by the user.

like this,
All Item In Inventory From 20/2/2010 To 28/2/2010

jggtz
February 28th, 2010, 12:06 PM
One way could be using a formula field...
Insert a new Formula Field, let's say MySubTitle
This formula's text could be "Trim('From dd/mmm/yyyy To dd/mmm/yyy')" or anything else
Now in your print code, before to view the report, place the next code

Dim CRCount as Integer
For CRCount = 0 To CRReport.DataDefinition.FormulaFields.Count - 1
Select Case CRReport.DataDefinition.FormulaFields.Item(CRCount).Name.ToString
Case "MySubTitle"
CRReport.DataDefinition.FormulaFields.Item(CRCount).Text = "Trim(" & Chr(39) & "From: " & Format(MyDate1, "dd/MMM/yyyy") & " To: " & Format(MyDate2, "dd/MMM/yyyy") & Chr(39) & ")"
End Select
Next CRCount

MyDate1 and MyDate2 come from the DatePickers
Chr(39) ---> single quote
JG

meax80
March 1st, 2010, 02:13 AM
thanks for replying. i have found a way to do it.

here is how.

i added a special filed (Report Title) to my report at design time.

then in my win form which contains the crystal report viewer i added this code

objRpt1.SummaryInfo.ReportTitle = "Item Issued Between " & DTP1.Value.Date & " and " & DTP2.Value.Date & "."

this works, but might not be the best way.

jggtz
March 1st, 2010, 01:44 PM
Thank you
I learn another way to do it