Suppressing Crystal report detail section at runtime

Discussion in 'Microsoft VB .NET' started by Bill Nguyen, Oct 7, 2003.

  1. Bill Nguyen

    Bill Nguyen Guest

    I have the need to suppress a Crystal report detail section at runtime (when
    user selects "Summary" instead of "Detail"). The report created in CR 8.5
    and loaded using .ReportDocument . I couldn't find anything in
    ReportDocument control regarding this function.
    Any suggestion is greatly appreciated.
    Bill
     
    Bill Nguyen, Oct 7, 2003
    #1
    1. Advertisements

  2. "Bill Nguyen" <> schrieb
    > I have the need to suppress a Crystal report detail section at
    > runtime (when user selects "Summary" instead of "Detail"). The report
    > created in CR 8.5 and loaded using .ReportDocument . I couldn't find
    > anything in ReportDocument control regarding this function.
    > Any suggestion is greatly appreciated.
    > Bill


    A CrystalDecisions.CrystalReports.Engine.ReportDocument object has a
    ReportDefinition property. It returns a
    CrystalDecisions.CrystalReports.Engine.ReportDocument.ReportDefinition
    object. The object has a Sections property. You can use a loop to process
    the sections. A section has a Kind property. The section that's "Kind"
    property is AreaSectionKind.Detail is the detail section.

    Or: When you create an instance of your derived ReportDocument, each section
    is added as a property. If you rename the detail section to "detail", you
    can access the section: MyDocument.Detail.

    The Sectionformat property of a Section object has a EnableSuppress
    property. You can set it to True to suppress the section.


    --
    Armin
     
    Armin Zingler, Oct 7, 2003
    #2
    1. Advertisements

  3. Bill Nguyen

    Bill Nguyen Guest

    Armin;
    Thanks for the tip.
    I used ReportDocument and it worked. However, there are some problems
    associated with this:

    You have to treat each report differently depending on the number of
    sections you have in it. There is no universal section name/label that you
    can use. For example, I have 1 report with 7 sections, another with 9 (I use
    sections.count to display the sections). The section count includes
    suppressed and non-suppressed sections. The .Sections(x), however, only
    counts non-suppressed sections. I don't know of any way to get section
    name/label so that I can just use the following code:

    reportDocument1.ReportDefinition.Sections("SECTION_NAME").SectionFormat.Enab
    leSuppress = True



    If this is possible, I can just label the section following a naming
    convention for all of my reports and the code will work for all of them.

    Thanks

    Bill



    "Armin Zingler" <> wrote in message
    news:...
    > "Bill Nguyen" <> schrieb
    > > I have the need to suppress a Crystal report detail section at
    > > runtime (when user selects "Summary" instead of "Detail"). The report
    > > created in CR 8.5 and loaded using .ReportDocument . I couldn't find
    > > anything in ReportDocument control regarding this function.
    > > Any suggestion is greatly appreciated.
    > > Bill

    >
    > A CrystalDecisions.CrystalReports.Engine.ReportDocument object has a
    > ReportDefinition property. It returns a
    > CrystalDecisions.CrystalReports.Engine.ReportDocument.ReportDefinition
    > object. The object has a Sections property. You can use a loop to process
    > the sections. A section has a Kind property. The section that's "Kind"
    > property is AreaSectionKind.Detail is the detail section.
    >
    > Or: When you create an instance of your derived ReportDocument, each

    section
    > is added as a property. If you rename the detail section to "detail", you
    > can access the section: MyDocument.Detail.
    >
    > The Sectionformat property of a Section object has a EnableSuppress
    > property. You can set it to True to suppress the section.
    >
    >
    > --
    > Armin
    >
     
    Bill Nguyen, Oct 8, 2003
    #3
  4. "Bill Nguyen" <> schrieb im Newsbeitrag
    news:...
    > Armin;
    > Thanks for the tip.
    > I used ReportDocument and it worked. However, there are some problems
    > associated with this:
    >
    > You have to treat each report differently depending on the number of
    > sections you have in it. There is no universal section name/label that you
    > can use. For example, I have 1 report with 7 sections, another with 9 (I

    use
    > sections.count to display the sections). The section count includes
    > suppressed and non-suppressed sections. The .Sections(x), however, only
    > counts non-suppressed sections.


    I can't repro this. The Sections property contains all sections, no matter
    if suppressed or not. I used the following code:

    Dim rpt As New CrystalReport2
    Dim sec As CrystalDecisions.CrystalReports.Engine.Section

    Debug.WriteLine("Before suppressing detail section:")
    Debug.WriteLine(rpt.ReportDefinition.Sections.Count())

    For Each sec In rpt.ReportDefinition.Sections
    Debug.WriteLine(sec.Name)
    Next

    rpt.detail.SectionFormat.EnableSuppress = True

    Debug.WriteLine("After suppressing detail section:")
    Debug.WriteLine(rpt.ReportDefinition.Sections.Count())

    For Each sec In rpt.ReportDefinition.Sections
    Debug.WriteLine(sec.Name)
    Next


    Output:

    Before suppressing detail section:
    5
    Section1
    Section2
    detail
    Section4
    Section5
    After suppressing detail section:
    5
    Section1
    Section2
    detail
    Section4
    Section5


    > I don't know of any way to get section
    > name/label so that I can just use the following code:
    >
    >

    reportDocument1.ReportDefinition.Sections("SECTION_NAME").SectionFormat.Enab
    > leSuppress = True


    This works for me:
    rpt.ReportDefinition.Sections("detail").SectionFormat.EnableSuppress = True


    > If this is possible, I can just label the section following a naming
    > convention for all of my reports and the code will work for all of them.


    I'm not a fan of "late binding". Means, if one of your report (mistakenly)
    has a different name, or you wrote the wrong section name in your code, the
    compiler can't find this error, whereas using the typed reference using
    "report.detail." can be checked at compile time. But that's up to you, I can
    only say that the code above worked for me.

    --
    Armin
     
    Armin Zingler, Oct 8, 2003
    #4
  5. Bill Nguyen

    BenoitM Guest

    hi !

    the simplest way is to create a boolean parameter and use this param inside the 'supress' property
    of your detail section (using a formula)

    "Bill Nguyen" <> wrote in message news:...
    > I have the need to suppress a Crystal report detail section at runtime (when
    > user selects "Summary" instead of "Detail"). The report created in CR 8.5
    > and loaded using .ReportDocument . I couldn't find anything in
    > ReportDocument control regarding this function.
    > Any suggestion is greatly appreciated.
    > Bill
    >
    >
     
    BenoitM, Oct 8, 2003
    #5
  6. Bill Nguyen

    Bill Nguyen Guest

    Thanks a lot, Armin.
    I'll try this and let you know.
    Bill

    "Armin Zingler" <> wrote in message
    news:%...
    >
    > "Bill Nguyen" <> schrieb im Newsbeitrag
    > news:...
    > > Armin;
    > > Thanks for the tip.
    > > I used ReportDocument and it worked. However, there are some problems
    > > associated with this:
    > >
    > > You have to treat each report differently depending on the number of
    > > sections you have in it. There is no universal section name/label that

    you
    > > can use. For example, I have 1 report with 7 sections, another with 9 (I

    > use
    > > sections.count to display the sections). The section count includes
    > > suppressed and non-suppressed sections. The .Sections(x), however, only
    > > counts non-suppressed sections.

    >
    > I can't repro this. The Sections property contains all sections, no matter
    > if suppressed or not. I used the following code:
    >
    > Dim rpt As New CrystalReport2
    > Dim sec As CrystalDecisions.CrystalReports.Engine.Section
    >
    > Debug.WriteLine("Before suppressing detail section:")
    > Debug.WriteLine(rpt.ReportDefinition.Sections.Count())
    >
    > For Each sec In rpt.ReportDefinition.Sections
    > Debug.WriteLine(sec.Name)
    > Next
    >
    > rpt.detail.SectionFormat.EnableSuppress = True
    >
    > Debug.WriteLine("After suppressing detail section:")
    > Debug.WriteLine(rpt.ReportDefinition.Sections.Count())
    >
    > For Each sec In rpt.ReportDefinition.Sections
    > Debug.WriteLine(sec.Name)
    > Next
    >
    >
    > Output:
    >
    > Before suppressing detail section:
    > 5
    > Section1
    > Section2
    > detail
    > Section4
    > Section5
    > After suppressing detail section:
    > 5
    > Section1
    > Section2
    > detail
    > Section4
    > Section5
    >
    >
    > > I don't know of any way to get section
    > > name/label so that I can just use the following code:
    > >
    > >

    >

    reportDocument1.ReportDefinition.Sections("SECTION_NAME").SectionFormat.Enab
    > > leSuppress = True

    >
    > This works for me:
    > rpt.ReportDefinition.Sections("detail").SectionFormat.EnableSuppress =

    True
    >
    >
    > > If this is possible, I can just label the section following a naming
    > > convention for all of my reports and the code will work for all of them.

    >
    > I'm not a fan of "late binding". Means, if one of your report (mistakenly)
    > has a different name, or you wrote the wrong section name in your code,

    the
    > compiler can't find this error, whereas using the typed reference using
    > "report.detail." can be checked at compile time. But that's up to you, I

    can
    > only say that the code above worked for me.
    >
    > --
    > Armin
    >
     
    Bill Nguyen, Oct 8, 2003
    #6
  7. Bill Nguyen

    Bill Nguyen Guest

    Benoit;
    I created a parameter "p_suppress" in the report and used the following
    codes (from Brian's CR book online webpage). Got error
    "CrystalDecisions.Shared - Invalid Object type"
    What did I do wrong?
    Thanks
    Bill
    --------------------

    dim rptSum as boolean
    *** actually, rptSUM is passed from the calling sub.

    reportDocument1.Load(crRptName)

    Dim ParameterFields As CrystalDecisions.Shared.ParameterFields

    Dim ParameterField As CrystalDecisions.Shared.ParameterField

    ParameterFields = New CrystalDecisions.Shared.ParameterFields

    ParameterField = New CrystalDecisions.Shared.ParameterField

    ParameterField.ParameterFieldName = "p_suppress"

    ParameterField.CurrentValues.Add(rptSum)

    ParameterFields.Add(ParameterField)

    With myCrystal.CrystalReportViewer1

    ..ReportSource() = reportDocument1

    ..SelectionFormula = mSelection

    ..ParameterFieldInfo = ParameterFields

    ..RefreshReport()

    End With

    "BenoitM" <> wrote in message
    news:...
    > hi !
    >
    > the simplest way is to create a boolean parameter and use this param

    inside the 'supress' property
    > of your detail section (using a formula)
    >
    > "Bill Nguyen" <> wrote in message

    news:...
    > > I have the need to suppress a Crystal report detail section at runtime

    (when
    > > user selects "Summary" instead of "Detail"). The report created in CR

    8.5
    > > and loaded using .ReportDocument . I couldn't find anything in
    > > ReportDocument control regarding this function.
    > > Any suggestion is greatly appreciated.
    > > Bill
    > >
    > >

    >
    >
     
    Bill Nguyen, Oct 9, 2003
    #7
  8. Bill Nguyen

    Bill Nguyen Guest

    Found problem! I forgot to add the discretevalue .
    now I have a new problem, The report still prompts for the value of
    p_suppress (True or False). In VB6, you can suppress it. I just don't know
    how to do it in VB.NET.
    Please help.
    Thanks
    Bill

    "Bill Nguyen" <> wrote in message
    news:...
    > Benoit;
    > I created a parameter "p_suppress" in the report and used the following
    > codes (from Brian's CR book online webpage). Got error
    > "CrystalDecisions.Shared - Invalid Object type"
    > What did I do wrong?
    > Thanks
    > Bill
    > --------------------
    >
    > dim rptSum as boolean
    > *** actually, rptSUM is passed from the calling sub.
    >
    > reportDocument1.Load(crRptName)
    >
    > Dim ParameterFields As CrystalDecisions.Shared.ParameterFields
    >
    > Dim ParameterField As CrystalDecisions.Shared.ParameterField
    >
    > ParameterFields = New CrystalDecisions.Shared.ParameterFields
    >
    > ParameterField = New CrystalDecisions.Shared.ParameterField
    >
    > ParameterField.ParameterFieldName = "p_suppress"
    >
    > ParameterField.CurrentValues.Add(rptSum)
    >
    > ParameterFields.Add(ParameterField)
    >
    > With myCrystal.CrystalReportViewer1
    >
    > .ReportSource() = reportDocument1
    >
    > .SelectionFormula = mSelection
    >
    > .ParameterFieldInfo = ParameterFields
    >
    > .RefreshReport()
    >
    > End With
    >
    > "BenoitM" <> wrote in message
    > news:...
    > > hi !
    > >
    > > the simplest way is to create a boolean parameter and use this param

    > inside the 'supress' property
    > > of your detail section (using a formula)
    > >
    > > "Bill Nguyen" <> wrote in message

    > news:...
    > > > I have the need to suppress a Crystal report detail section at runtime

    > (when
    > > > user selects "Summary" instead of "Detail"). The report created in CR

    > 8.5
    > > > and loaded using .ReportDocument . I couldn't find anything in
    > > > ReportDocument control regarding this function.
    > > > Any suggestion is greatly appreciated.
    > > > Bill
    > > >
    > > >

    > >
    > >

    >
    >
     
    Bill Nguyen, Oct 9, 2003
    #8
  9. Bill Nguyen

    BenoitM Guest

    You can use the 'SetParameterValue' method of the ReportDocument object to pass param infos more
    easily ...


    "Bill Nguyen" <> wrote in message news:%...
    > Found problem! I forgot to add the discretevalue .
    > now I have a new problem, The report still prompts for the value of
    > p_suppress (True or False). In VB6, you can suppress it. I just don't know
    > how to do it in VB.NET.
    > Please help.
    > Thanks
    > Bill
    >
    > "Bill Nguyen" <> wrote in message
    > news:...
    > > Benoit;
    > > I created a parameter "p_suppress" in the report and used the following
    > > codes (from Brian's CR book online webpage). Got error
    > > "CrystalDecisions.Shared - Invalid Object type"
    > > What did I do wrong?
    > > Thanks
    > > Bill
    > > --------------------
    > >
    > > dim rptSum as boolean
    > > *** actually, rptSUM is passed from the calling sub.
    > >
    > > reportDocument1.Load(crRptName)
    > >
    > > Dim ParameterFields As CrystalDecisions.Shared.ParameterFields
    > >
    > > Dim ParameterField As CrystalDecisions.Shared.ParameterField
    > >
    > > ParameterFields = New CrystalDecisions.Shared.ParameterFields
    > >
    > > ParameterField = New CrystalDecisions.Shared.ParameterField
    > >
    > > ParameterField.ParameterFieldName = "p_suppress"
    > >
    > > ParameterField.CurrentValues.Add(rptSum)
    > >
    > > ParameterFields.Add(ParameterField)
    > >
    > > With myCrystal.CrystalReportViewer1
    > >
    > > .ReportSource() = reportDocument1
    > >
    > > .SelectionFormula = mSelection
    > >
    > > .ParameterFieldInfo = ParameterFields
    > >
    > > .RefreshReport()
    > >
    > > End With
    > >
    > > "BenoitM" <> wrote in message
    > > news:...
    > > > hi !
    > > >
    > > > the simplest way is to create a boolean parameter and use this param

    > > inside the 'supress' property
    > > > of your detail section (using a formula)
    > > >
    > > > "Bill Nguyen" <> wrote in message

    > > news:...
    > > > > I have the need to suppress a Crystal report detail section at runtime

    > > (when
    > > > > user selects "Summary" instead of "Detail"). The report created in CR

    > > 8.5
    > > > > and loaded using .ReportDocument . I couldn't find anything in
    > > > > ReportDocument control regarding this function.
    > > > > Any suggestion is greatly appreciated.
    > > > > Bill
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    BenoitM, Oct 10, 2003
    #9
  10. Bill Nguyen

    rajeshc

    Joined:
    Jun 6, 2012
    Messages:
    1
    Likes Received:
    0
    I want to suppress whole detail section if my group is suppressed. I suppressed group on this condition: if purchase date > the date entered in parameter field.
     
    rajeshc, Jun 6, 2012
    #10
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. solex

    Master-> Detail-> Detail with datagrids

    solex, Mar 3, 2004, in forum: Microsoft VB .NET
    Replies:
    1
    Views:
    260
    Ken Tucker [MVP]
    Mar 4, 2004
  2. Meena
    Replies:
    3
    Views:
    1,682
    EricJ
    Apr 28, 2004
  3. Stu
    Replies:
    2
    Views:
    377
  4. Ray
    Replies:
    2
    Views:
    261
    Bernie Yaeger
    Apr 7, 2005
  5. John Smith
    Replies:
    0
    Views:
    853
    John Smith
    Jan 17, 2007
Loading...

Share This Page