How to suppress Details sections at run-time

Srikanthv

Member
Joined
Jul 3, 2006
Messages
18
Programming Experience
5-10
I have Details sections in my crystal report
Details a
Details b
Details c
...
....
Details i
I have to supress( or hide) Details sections on conditionally at run time.
Like ex:
if condn=1 then
Details a = suppress (or) hide // I dont want to show this details section
else if condn =2 then
Details b= suppress (or) hide // I dont want to show this details section
else
Details c = suppress (or) hide // I dont want to show this details section
end if
Please provide me sample code.
 
Last edited:
You could pass parameters for each section.
Use your example "if" structure to set report parameters or variables to true or false based on your conditions at runtime.
In the report, suppress the section if the parameter is true.

Formula editor for section supress [x-2]:
If @SectA = true then '@SectA is a boolean parameter passed from VB.net
formula = true 'Supress is true
end if


You can be as creative as you want with the supress formula. Pass the report a string, an integer or a boolean parameter(s). Then just check the parameter in the formula editor for the detail section supression and set the formula to true or false based on the parameter value.

There are many posts here on passing a parameter to crystal reports.


Hope that helps.
 
In my case I have combobox items, By selecting combobox, I will know that which details section need to hide.

Is there code for hide the details sections individually.
like

if codn =1 the
Hide "details a" and show "details b"
else
show "details a" and hide "details b"
end if

provide me some code on this
 
You will not be hiding the sections from vb.net.

You will be setting variables based on the combobox values, passing the values of the variables to the report through parameters, and suppressing the sections based on the values of the parameters.

Do you understand the basic concept?
Have you passed parameters to a report before?
Where do you need help?
 
Do you understand the basic concept?
I understand concept, I never worked on like this situation

Have you passed parameters to a report before?
No, This is the first time

Where do you need help?
Passing parameters to report for suppress or hide the details setion,
Do i need keep each formal for each section. If possible post sample code or project
 
Create parameters on your report called "SectA" and "SectB" and make them boolean.
In you code where you are calling the report, before you call the report:

VB.NET:
Dim rpt1 AsNew CrystalReport1 ' or your report name.

if YourCondition1 then
  rpt1.SetParameterValue("SectA", true)
  rpt1.SetParameterValue("SectB", false)
else
  rpt1.SetParameterValue("SectA", false)
  rpt1.SetParameterValue("SectB", true)
end if
On the report you need to edit the detail section and click on the [x-2] button under the supress option for each section.

You will create a formula something like: (i'm not at my workstation so I can't test)

VB.NET:
If @SectA = true then
  formula = true
else
  formula = false
end if.
All it says is that if parameter "sectA" is true supress detail Section A, if parameter "sectA" is false do not supress detail Section A.

Do the same for Detail Section B and let me know how it works...
 
thanks David,

I understand clearly thru code. Its good. If you give code for formula (suppress code required {formula = true}). Its gr8 helpfull to me.
 
Last edited:
Right click on the detail section and select format section.
Second checkbox down is "Suppress (No-Drill Down)" => press the X-2 button to open the formula editor.
Switch the formula editor from Crystal Syntax to Basic Syntax.

Add this code.

VB.NET:
if {?SectA}=true then
formula = true
else
formula = false 
end if
The x-2 should turn red to show there is a formula there.
Do the same for section B.

If you are interested in more stuff like this, research "crystal reports conditional formatting"
 
Her I got another problem, I am using
CrystalDecisions.Windows.Forms.CrystalReportViewer object version 11. I didnot find property or method for setparameter value to report. How to set parameter value to CrystalReportViewer.
 
The parameter is a part of the report, not a part of the report viewer. The report viewer has nothing to do with parameters, it only displays the specified report.
You need to setparameter for a report...

Dim rpt1 As New YourReportName
rpt1.SetParameterValue("SectA", true)


YourReportName is the actual name of the report the parameter exists in... default is CrystalReport1.

you set the viewer to display the report:
CrystalReportViewer1.ReportSource = rpt1
CrystalReportViewer1.Refresh()
 
David,

Everytime I am getting Parameter window to set parameter values while running application. I dont want to show this window while running application

please see the below attachement.
 

Attachments

  • default.GIF
    default.GIF
    31.9 KB · Views: 33
show me the code where you are trying to set the value of the parameters..

I need more information.

Like this:
On my form I have checkboxes the user sets which sections to show with.
I set global variables to true or false depending on the checkbox state.
Then I press a button and I call the form with the report viewer.
Then I set all the parameters for the report (from the values of the global variables) during the report viewers load event and display the report.


p.s.
You should be setting the parameters right before you set the CrystalReportViewer1.ReportSource

Also,
your code should be rpt1.SetParameterValue("SectionA", true) names must match exactly... DetailsN,DetailsO, and so on.
 
Last edited:
I noticed in your attached image the first prompt is for "SectionA" and over on the right is "DetailsM". What is the name of the parameter on the report?
 
Thanks David,

I problem got solved.I fogot set all parameters on condition. Actually i set on single parameter what i req. Now I set all parameters on each condition. So its working fine.

Thanks again David
 
No problem, glad to hear it.
You'll be a parameters expert in no time. Parameters are very useful in record selection formulas... food for thought.
 
Back
Top