This is a migrated thread and some comments may be shown as answers.

Problem with visibility that SubReport

5 Answers 160 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Lucas
Top achievements
Rank 1
Lucas asked on 02 Oct 2012, 12:31 PM
HI,
First, sorry for my english google translator.

My problem is that I'm trying to set the visibility of a subreport this by DataBinding. Except that Telerik is not updating the fields that I'm by setting the visibility, they still visible. I tried other ways, but then when I exchange their visibility to false when returns to be true, the interface fields do not return true.

Here is a piece of my code to see if you can help me.

I'm have a List

C#

I have the list, and I want the subreport becomes invisible when the list is empty.

detail is the name of the group that want to become invisible

 

 

private void subReport1_ItemDataBinding_1(object sender, EventArgs e)
        {
            var table = sender as Telerik.Reporting.Processing.SubReport;
            if (table == null) return;
 
            var group = table.DataObject.RawData as CommissionPaymentValue;
            if (group == null) return;
 
            var items = group.CommissionPaymentValueItem;
 
            detail.Visible = items.Count > 0;
 
            this.commissionPaymentValueItemReport1.Report.DataSource = items.OrderByDescending(a => a.TypeItem);
        }

 I know there are threads with the same problems, but still could not solve my.

att Lucas

5 Answers, 1 is accepted

Sort by
0
Accepted
Elian
Telerik team
answered on 05 Oct 2012, 04:49 PM
Hi Lucas,

Refer to the following code for hiding a SubReport programmatically if no data:
private void subReport1_ItemDataBound(object sender, System.EventArgs e)
{
   Processing.SubReport subReport = (Processing.SubReport)sender;
   Processing.Report report = (Processing.Report)subReport.InnerReport;
   subReport.Visible = report.Items.Find("detail", true).Length > 0;
}

If you want to hide the whole section that contains the SubReport, for e.g. you still have to use the processing objects.
 
private void subReport1_ItemDataBound(object sender, System.EventArgs e)
{
   Processing.SubReport subReport = (Processing.SubReport)sender;
   Processing.Report report = (Processing.Report)subReport.InnerReport;
   var detailSection = subReport.ParentElement as Processing.DetailSection;
   detailSection.Visible = report.Items.Find("detail", true).Length > 0;
}

 
Regards,
Elian
the Telerik team

HAPPY WITH TELERIK REPORTING? Do you feel that it is fantastic? Or easy to use? Or better than Crystal Reports? Tell the world, and help fellow developers! Write a short review about Telerik Reporting and Telerik Report Designer in Visual Studio Gallery today!

0
Lucas
Top achievements
Rank 1
answered on 19 Oct 2012, 01:05 PM
Thanks Elian, solved my problem
0
Bryon
Top achievements
Rank 2
answered on 19 Dec 2016, 07:27 PM

Hi - I am trying to implement this in VB.  I have an old version of reporting Q1 2012 (6.0.12.215)  and it keeps telling me that Items is not a member of reports... Can someone tell me what I need to do to get the compiler to accept?  Thank you.

 

Private Sub RptChildListSub1_ItemDataBound(sender As Object, e As EventArgs) Handles RptChildListSub1.ItemDataBound
                Dim subReport As Processing.SubReport = DirectCast(sender, Processing.SubReport)
                Dim report As Processing.Report = DirectCast(subReport.InnerReport, Processing.Report)
                subReport.Visible = report.Items.Find("detail", True).Length > 0
End Sub

Private Sub RptChildListSub1_ItemDataBound(sender As Object, e As System.EventArgs)
                Dim subReport As Processing.SubReport = DirectCast(sender, Processing.SubReport)
                Dim report As Processing.Report = DirectCast(subReport.InnerReport, Processing.Report)
                Dim detailSection = TryCast(subReport.ParentElement, Processing.DetailSection)
                detailSection.Visible = report.Items.Find("detail", True).Length > 0
End Sub

 

0
Bryon
Top achievements
Rank 2
answered on 19 Dec 2016, 07:32 PM

 

I am trying to do this in vb.  I have an older version of Telerik Reporting (Q1 2012 - 6.0.12.215)  However I keep getting compile errors that Items is not a member of reports.  Can someone assist me?

Thanks in advance.

 

Private Sub subReport1_ItemDataBound(sender As Object, e As System.EventArgs)
                Dim subReport As Processing.SubReport = DirectCast(sender, Processing.SubReport)
                Dim report As Processing.Report = DirectCast(subReport.InnerReport, Processing.Report)
                Dim detailSection = TryCast(subReport.ParentElement, Processing.DetailSection)
                detailSection.Visible = report.Items.Find("detail", True).Length > 0
End Sub

 

Private Sub RptChildListSub1_ItemDataBound(sender As Object, e As EventArgs) Handles RptChildListSub1.ItemDataBound
                Dim subReport As Processing.SubReport = DirectCast(sender, Processing.SubReport)
                Dim report As Processing.Report = DirectCast(subReport.InnerReport, Processing.Report)
                subReport.Visible = report.Items.Find("detail", True).Length > 0
End Sub

0
Stef
Telerik team
answered on 20 Dec 2016, 09:53 AM
Hello Danielle,

The code snippet checks if the report has a section/item named 'detail' in its structure rather than checking the current processing sections.

Please use the approach for sub reports suggested in How to show 'No Data Message' or hide an item in case of No data.

Regards,
Stef
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Lucas
Top achievements
Rank 1
Answers by
Elian
Telerik team
Lucas
Top achievements
Rank 1
Bryon
Top achievements
Rank 2
Stef
Telerik team
Share this question
or