CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2010
    Posts
    3

    use variables from winform in the CrystalReportViewer

    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

  2. #2
    Join Date
    Jul 2005
    Posts
    1,083

    Re: use variables from winform in the CrystalReportViewer

    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
    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
    Last edited by jggtz; February 28th, 2010 at 01:09 PM.

  3. #3
    Join Date
    Feb 2010
    Posts
    3

    Re: use variables from winform in the CrystalReportViewer

    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.

  4. #4
    Join Date
    Jul 2005
    Posts
    1,083

    Re: use variables from winform in the CrystalReportViewer

    Thank you
    I learn another way to do it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured